how could i restart a console application?
if(...)
{
...
}
else
{
<restart program here>
}
how could i restart a console application?
if(...)
{
...
}
else
{
<restart program here>
}
This is prpbably not what you want, I am new to C++. I don't know about restarting a console app but is keeping it going any use to you?
-------------------------------------------
char user_option = 'Y';
While (user_option == 'Y' || user_option =='y'){
code in here
cout<<"Continue program Y or N";
cin >> user_option;
}
---------------------------------------
Hope this helps!
-Colin
Put all the code inside your main in a while loop or do..while loop. Then, if the user wants to quit, break out of the program. At least that's the way I'd do it. However, make sure you free all allocated memory at the end of the loop.
Thats what win32 apps does to... msg-loop...
just call main().
Code:#include <iostream>//for cout and cin char makeLower(char letter); int YorN(); //ahh, the yes or no question /////////////////// int main() { cout<<"hi, do you want to restart"; if(YorN()) { main(); //restart } return 0; } ///////////////////////////////////////////////// char makeLower(char letter) { if (((int)letter)>64 && ((int)letter)<91) //checks if its a capital { (int)letter=(int)letter+32; //makes it a small letter return letter; } else { return letter; } } //////////////////////////////////////////////////// int YorN() //ahh, the yes or no question { char anwser = 'n'; cin>>anwser; if (makeLower(anwser)=='y') //if the letter, in lowercase, is y { return 1; //if it's y, return a 1 } else { return 0; } }
Bart, wouldn't that cause you to creep slowly up the stack? A recursive main() would get costly after a few calls.
golfinguy and ninebit had the right idea. Use a big loop to control everything.
I would never, ever just call main(). Although you could, I wouldn't. b/c like Imperito said, it can get costly.
>I would never, ever just call main(). Although you could
No, if you're coding in C++ you couldn't. It's against the law.