![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jun 2006
Location: at my computer desk
Posts: 138
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
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?
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
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.
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jul 2005
Posts: 158
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#5 |
|
Expert Programmer
|
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).
__________________
|
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 852
Rep Power: 4
![]() |
You need to post your code, it is probably not getting to the system call.
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Jun 2006
Location: at my computer desk
Posts: 138
Rep Power: 3
![]() |
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");
}![]() |
|
|
|
|
|
#8 |
|
Professional Programmer
|
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 |
|
|
|
|
|
#9 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
Your problem is that system("pause") comes after you return. Put it before that.
else goto Cont; Cont: //... else goto Continue; Continue: Prompt: //... goto Prompt; And use some indentation. |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Jun 2006
Location: at my computer desk
Posts: 138
Rep Power: 3
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|