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
4 Respostas
+ 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;
}
+ 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!
0
Thanks so far, I will test it and reply
0
doesn't work the way I want