Guys why this code become an infinite loop? I'm learning C++ so if you can explain the solution, for me would be very important!
// Odd_or_Even.cpp : This program determinate if a number is Odd or Even
//
#include "stdafx.h"
#include "std_lib_facilities.h";
int main()
{
int num = 0;
bool repeat = true;
while (repeat == true)
{
cout << "Please enter an integer to determinate if it's odd or even: ";
cin >> num;
cout << "\nReading data...";
if (!cin) {
cout << "Failed\n";
cout << "There is some problem with the number, sorry!\n";
cout << "\n";
cin.clear();
}
else
{
cout << "God job, now stop lose time.";
repeat = false;
}
}
keep_window_open();
return 0;
}
Thanks!
EDIT: ok i writed the if for block the loop, but if you try to write a letter, instead of a number, it still go in a loop!!