0
Continuation of the Program
This is what I want. At the end of my program, I want the user to be asked if he wants to run the program again. And if he says 'yes' , the program should begin again. If 'no', program should be closed itself. How to do this?
2 Respuestas
+ 4
here's an example written in C
should be pretty straightforward to write it in any other language
void prog(); // function prototype
int main(){
char continue;
do{
prog();
printf("run again? [y/n]: ");
scanf("%c", &continue);
}while(continue == 'y' || continue == 'Y');
}
void prog(){
// your code to run multiple times goes here
}
edit: didn't notice the python tag (silly me)
def prog():
# code goes here
while true:
prog()
cont = input("run again? [y/n]")
if cont != y:
break
+ 1
put everything in a loop and ask again to restart things.
you can put everything in a function and call it recursively till a condition is true.