Hello everyone. I was, for a while, solving this problem our teacher had given us. But unfortunately, I keep failing. Our teacher had said that our program is not supposed to accept character data types whenever entered. But it keeps accepting. I would really be grateful if you could help me. Its a code that accepts building types(blg) then accepts kwh present(kwhpres) and previous(kwhprev) and compute for the respective payment(am). Here is my code:
You'll need some sort of while loop in there to validate the input and stop the program from progressing until a number has been entered.
Something like:
1 2 3 4 5 6 7 8 9 10
int my_int;
cout << "Please enter an integer number: ";
while(!(cin >> my_int))
{
cout << "Invalid input, try again: ";
cin.clear();
cin.ignore(1000, '\n');
}
You'll need to adapt it for your code. If you need extra conditions (say, you don't want a negative number to be entered), just add them as or conditions for that while statement.