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; }
5 Antworten
+ 2
You can use try/catch block
https://www.sololearn.com/learn/CPlusPlus/1918/
+ 1
what do you want to happen if input is not a number
,....input until It is a number or exit out?
0
all i want to know is to give a message that error please enter a number