0

I have a question and also i have a code..just wanna ask how could I insert the error code using Cpp

//How could I insert the error message if the user would have // enter a alphabet or special characters #include <iostream> using namespace std; int main() { int evensum =0; int oddsum =0; int num=0; char error; for (int i = 1;i < 5; i++) { cout <<" Please enter a number: "; cin >> num; if (i% 2==0) { evensum = evensum+num; } else{ oddsum = oddsum+num; } else if{ cout << you enter an error<<endl; } } cout <<"total of all the entered numbers is: " << evensum<< endl; cout <<"total of all the entered numbers is: " << oddsum<< endl; return 0; }

13th Dec 2020, 12:16 PM
Benito Estimo
Benito Estimo - avatar
5 Antworten
13th Dec 2020, 12:30 PM
Simba
Simba - avatar
+ 1
what do you want to happen if input is not a number ,....input until It is a number or exit out?
13th Dec 2020, 12:55 PM
rodwynnejones
rodwynnejones - avatar
0
all i want to know is to give a message that error please enter a number
14th Dec 2020, 3:49 AM
Benito Estimo
Benito Estimo - avatar