How can I loop this to make it work where when the user enters a negative value for cin statements, it checks and tells the user they have an invalid input and to try again, and loops around. I already have a do while loop and I need to make it to where the program will check for invalid inputs like negative values and it will loop again and ask the questions until they enter the right value.
while(input < 0)
{
std::cin >> input;
if(std::cin.fail())
{
std::cin.clear(); //this is to clear the stream error state in case someone enters in a letter instead of a numerical value
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //this exacts all the characters from the stream so we start out with a fresh stream to get the input
}
}