First off, I am very new to C++ (I literally started learning it 2 hours ago, so go easy on me)
This simple program is supposed to check whether or not the user input is a valid number between 0 and 101 and simply respond, valid or invalid.
#include <iostream>
int main() {
bool isValidNum = false;
do
{
std::cout << "How many samples were collected?\n";
int numOfSamples;
std::cin >> numOfSamples;
isValidNum = (numOfSamples > 0 && numOfSamples < 101);
if (isValidNum) {
std::cout << "valid\n";
}
else {
std::cout << "invalid\n";
}
} while (isValidNum == false);
}
It works. Except that if you put anything other than an integer it loops infinitely.
I may have over stretched myself by using a do/while loop whilst so unfamiliar with this language.
What is wrong with the condition flow? (I assume i'm just being incredibly smoothbrained and need some coffee)