Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   my console apps just close...system("pause") doesnt work (http://www.programmingforums.org/showthread.php?t=10577)

angry_asian Jun 29th, 2006 8:40 PM

my console apps just close...system("pause") doesnt work
 
whenever i open one of my simple console apps, and theres a prompt, if i input, right after the comp outputs (be4 i can even see it) it instantaneously closes (unless running in debug mode, im talkin about just opening the .exe)
i added
system("pause");
and it compiled :)
but didnt work :(...it still closed instantaneously after inputing a value

Jimbo Jun 29th, 2006 8:49 PM

Assuming you're using VS, it will close anyways in debug mode. It's when you run it in non-debug mode (but still from the IDE) that it stays open. Maybe post your code?

Sane Jun 29th, 2006 9:23 PM

It might be executing a runtime error. Something that the compiler doesn't pick up, because it's conditional upon what happens inside the execution.

teencoder Jun 29th, 2006 9:50 PM

system("pause") only works in Windows. You could try using cin.get(). Those are the only standard methods I know.

crawforddavid2006 Jun 29th, 2006 10:07 PM

Try this
:

system("PAUSE");
return EXIT_SUCCESS;


also make sure that system is all lower case ( i don't know if that matters but it might help).

The Dark Jun 29th, 2006 10:17 PM

You need to post your code, it is probably not getting to the system call.

angry_asian Jun 30th, 2006 12:26 AM

heres my code then dark:
:

/*****************
Program: days.exe
File: days1.cpp
Funciton: asks user to input a number representing day of week and set that as vacation...if day is already off then it will reprompt
Description: simple program
Author: Sreenath Pillai
Environment: Microsoft Visual C++ 5
Notes: will change goto and make 0 return an error to console....0 works, i dunno why the heck it does, but o well...
Version: 0.1
Revisions: none
***************/
#include<iostream>
using namespace std;
typedef unsigned short int USHORT;
int OhGosh(std::string StupidUser) // Prm753's function...it OWNS!!!
{
      std::cerr << StupidUser << std::endl;
      return 1;
}
int main()
{
enum Days {Sunday=1, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
const char *dayNames[8] = {"", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
Prompt:
Days y;
USHORT x;
cout <<"What day of the week would you like off (1=Sunday to 7=Saturday)?";
cin >> x;
if ( !std::cin.good() ) return OhGosh("Why couldn't you have entered a number?");
else goto Cont;
Cont:
if (x<1, x>7)
{
        cout <<"\nPlease enter a number between 1 (Sunday) and 7 (Saturday)\n";
goto Prompt;
}
else
goto Continue;
Continue:
y = Days(x);
if (y == Sunday || y == Saturday)
{
        cout <<"\nYou already have weekends off!\n";
        goto Prompt;
}
else
cout<<"\nOkay, you now have\t" << dayNames[y] << "\toff\n";
return 0;
system ("pause");
}

the question is misunderstood...the program worked but quit AFTER it worked...in debug it pauses til i hit a key but oprning it from windows explorer it prompts, i enter the # and it terminates....now i enter a wrong number and the error message that i programmed successfully comes meaning that the prgm itself works...just that after solving it closes immediately and i want it to pause that all :D

Prm753 Jun 30th, 2006 12:32 AM

You don't notice anything wrong with where return 0; is located? And please use a switch() statement.

Jimbo Jun 30th, 2006 12:33 AM

Your problem is that system("pause") comes after you return. Put it before that.

:

else goto Cont;
Cont:
//...
else
goto Continue;
Continue:

Got to go.
:

Prompt:
//...
goto Prompt;

Use a loop.

And use some indentation.

angry_asian Jun 30th, 2006 12:36 AM

lol yeah gotta get in habit of indentation, read my comments my first revision is to get rid of gotos, already deleted cont and continue cause they did nothing lol....duno how to loop (syntax) but ill learn, i know the comcept pretty well from VB

adding prm function got me an error


All times are GMT -5. The time now is 8:05 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC