当我们输入int number时,以下程序将起作用。但是当我们输入字符时,如何显示错误信息? 我想在这个程序中输入字符时显示错误信息。 需要做什么?
#include <iostream>
using namespace std;
int main()
{
int num1,num2,num3;
char c;
A:
cout << "\nEnter the three numbers:" <<endl;
cout <<"Num1: ";
cin>>num1;
cout <<"Num2: ";
cin>>num2;
cout <<"Num3: ";
cin>>num3;
if(num1==c)goto A;
if (num1 >num2 && num1>num3)cout<<"The largest number is: " <<num1<<endl;
else if(num2 >num1 && num2>num3)cout<<"The largest number is: " <<num2<<endl;
else if(num3 >num1 && num3>num2)cout<<"The largest number is: " <<num3<<endl;
if(num1 <num2 && num1<num3)cout<<"The smallest number is: " <<num1<<endl;
else if(num2 <num1 && num2<num3)cout<<"The smallest number is: "
<<num2<<endl;
else if(num3 <num1 && num3<num2)cout<<"The smallest number is: "
<<num3<<endl;
if(num1==num2 && num1<num3)cout<<"The smallest numbers are: " <<num1<<" and "
<<num2<<endl;
else if(num1==num3 && num1<num2)cout<<"The smallest numbers are: " <<num1<<"
and "<<num3<<endl;
else if(num2==num3 && num2<num1)cout<<"The smallest numbers are: " <<num2<<"
and "<<num3<<endl;
if(num1==num2 && num1>num3)cout<<"The largest numbers are: " <<num1<<" and "
<<num2<<endl;
else if(num1==num3 && num1>num2)cout<<"The largest numbers are: " <<num1<<"
and "<<num3<<endl;
else if(num2==num3 && num2>num1)cout<<"The largest numbers are: " <<num2<<"
and "<<num3<<endl;
if(num1==num2 && num2==num3)cout <<"You Can't enter same numbers\nPlease try
again"<<endl;
}