0

C++ Repeating the process by asking user

Hey guys I want to repeat the whole process after the user is answering with 'j' otherwise break it. I already tried several ways, but everytime the loop repeats the whole time without ending and with the old solution. How can I fix it? here is the code: http://pastebin.com/g62gxFJn

3rd Jan 2017, 2:38 PM
John
John - avatar
4 Answers
+ 6
int main() { char program_restart; do { // codes cout << "Do you want to restart your program? (Y/N)"; cin >> program_restart; } while (program_restart == 'Y'); return 0; }
3rd Jan 2017, 3:18 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
ok I got it now, the problem was with cin, when no integer was read. I had to include #include <limits> and add that: if (cin.fail()) { cin.clear(); cin.ignore(std::numeric_limits<long>::max(), '\n'); However thanks for your effort!
4th Jan 2017, 4:30 PM
John
John - avatar
0
Thanks so far, I will test it and reply
3rd Jan 2017, 3:23 PM
John
John - avatar
0
doesn't work the way I want
3rd Jan 2017, 3:55 PM
John
John - avatar