How do I make the program loop back | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do I make the program loop back

Instead of exiting after getting output, how do I make it to ask again if i would like to type new input or I want to exit, I use system("pause") for now but I know it sucks and i gotta exit and re-enter again when I want to use it multiple times. If its some long code then don't help me I will learn in time lol, if its short then I can learn it now.

12th Aug 2017, 7:21 AM
Djordje Zivkovic
Djordje Zivkovic - avatar
5 Answers
+ 5
loop and boolean bool quit = false; while(!quit) { // do stuff int choice; cin >> choice; if(choice == 0) { quit = true; } }
12th Aug 2017, 7:25 AM
jay
jay - avatar
+ 6
you can put your code where it says do stuff. it won't work on sololearn properly though. well it will but you will need to enter all possible choices.
12th Aug 2017, 7:33 AM
jay
jay - avatar
+ 4
sure. you dont need to give me credit if you dont want too. You would have got it eventually!
12th Aug 2017, 8:30 AM
jay
jay - avatar
+ 2
Thanks I made it work, I am still a beginner so I didn't understand how would it work if I put my code there like it would be just 1 time than quit, but then I remeber its a loop ;d Thanks dude, love this community, got 2 helps and finally finished my program(I guess its not pure mine because I got 2 helps lol ) Can I post it to code playground and credit you? :D
12th Aug 2017, 8:04 AM
Djordje Zivkovic
Djordje Zivkovic - avatar
0
Well it didn't quit but its just blank, I gotta make it if you continue it "restarts" and does the code all over again.
12th Aug 2017, 7:28 AM
Djordje Zivkovic
Djordje Zivkovic - avatar