restart the program
Printable View
restart the program
like exit the program and it re-execute it or...just go back to the beginning of the code?
restart as in?.....
rexecute the code from the top without quitting
You design your code well, so you don't need to restart. This is rather vague, to match your question ;)
Or you could get it to spawn a new copy itself.
Code:while(something)
{
YourCode();
}
I want the program to restart once it reaches the end. Like a calculator.
> restart once it reaches the end.
You want it to restart every time?
Code:while(1)
{
stuff
}
The topic you need to study is called "loops". There are for-loops, while-loops, do-while loops... So, you can also look-up "for", "do", and "while".
[EDIT]
LOOPING and CONDITIONAL EXECUTION/ CONDITIOAL BRANCHING are the two features that make programming valuable. (IMHO)
Here is an example of loop I used on a console program I made a while ago.
Thise is not the full code but I think its a good example on how you could do it for a calculator..Code:int main()
{
program();
return 0;
}
void program()
{
while (y != 'e')
{
menu();
cin >> y;
ans(y);
}
}
void menu() // display menu
{
cout <<endl<< "What would you like to do?" << '\n'<<endl;
cout << "[I] Input a date?" << endl;
cout << "[O] Output a date?" << endl;
cout << "[D] Delete a date?" << endl;
cout << "[E] Exit?" << endl << endl;
}
void ans(char y) // handles answers to menu
{
switch (y)
{
case 'i':
input();
break;
case 'o' :
output();
break;
case 'd' :
delet();
break;
case 'e' :
break;
}
}
i'm going to get really yelled at for this :)
void main() {
10 //beinging
//end
goto 10;
}
muhahaha
It physically hurts me.
>i'm going to get really yelled at for this
So why did you suggest it? void main is very wrong and there are more elegant solutions than goto in this situation.
-Prelude