Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 29th, 2006, 7:40 PM   #1
angry_asian
Hobbyist Programmer
 
Join Date: Jun 2006
Location: at my computer desk
Posts: 138
Rep Power: 3 angry_asian is on a distinguished road
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
angry_asian is offline   Reply With Quote
Old Jun 29th, 2006, 7:49 PM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
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?
Jimbo is offline   Reply With Quote
Old Jun 29th, 2006, 8:23 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,885
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Jun 29th, 2006, 8:50 PM   #4
teencoder
Hobbyist Programmer
 
teencoder's Avatar
 
Join Date: Jul 2005
Posts: 158
Rep Power: 0 teencoder is an unknown quantity at this point
system("pause") only works in Windows. You could try using cin.get(). Those are the only standard methods I know.
__________________
Geeks may not be cool now but in the long run they prosper.
teencoder is offline   Reply With Quote
Old Jun 29th, 2006, 9:07 PM   #5
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 582
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
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).
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Jun 29th, 2006, 9:17 PM   #6
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
You need to post your code, it is probably not getting to the system call.
The Dark is online now   Reply With Quote
Old Jun 29th, 2006, 11:26 PM   #7
angry_asian
Hobbyist Programmer
 
Join Date: Jun 2006
Location: at my computer desk
Posts: 138
Rep Power: 3 angry_asian is on a distinguished road
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
angry_asian is offline   Reply With Quote
Old Jun 29th, 2006, 11:32 PM   #8
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
You don't notice anything wrong with where return 0; is located? And please use a switch() statement.
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Jun 29th, 2006, 11:33 PM   #9
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
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.
Jimbo is offline   Reply With Quote
Old Jun 29th, 2006, 11:36 PM   #10
angry_asian
Hobbyist Programmer
 
Join Date: Jun 2006
Location: at my computer desk
Posts: 138
Rep Power: 3 angry_asian is on a distinguished road
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
angry_asian is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:43 PM.

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