I am trying to make a C++ sales calculator and for my if, else statement I have my "Purchase" as == to false at moment, i am a bit confused on how to get it so that when the user enters a non number (so like letters and such) then the loop will just reset and ask the user again to add a valid number answer and must plug in a number answer, and to repeat it again and again if the user doesn't put in a valid number answer.
std::cout << endl << "How much is the item you would like to purchase: $"; //purchase enter text
std::cin >> purchase; // we assume that the user enters a valid score
if (purchase == false) { // figure out the purchase == no number value so loop works correctly
cout << "Please select a state from the following list:";
}
else {
cout << "The entered cost is invalid..." << endl;
cout << endl << "How much is the item you would like to purchase: $";
cin >> purchase;
cout << "Please select a state from the following list:" << endl;
}
cout << "1.) Maryland" << endl;
cout << "2.) Virginia" << endl;
cout << "3.) North Carolina" << endl;
cout << "4.) South Carolina" << endl;
cout << "5.) Deleware" << endl;
cout << "6.) District of Columbia" << endl;
cout << "7.) Pennsylvania" << endl;
cout << "In which state is the purchase being made : ";
cin >> state_list;
// add state_list loop here with each state numbered