我正在创建自己的非常简单的程序,允许用户输入数值。目前代码工作得很好,但我需要一个验证 if else 语句。这就是我目前所拥有的;
#include <iostream>
#include <string>
using namespace std;
int main()
{
unsigned __int64 input = 0;
char str[] = "qwertyuiopasdfghjklzxcvbnm[]{};'#:@~,./<>?|!£$%^&*()";
cout << "Insert a number" << endl;
cin >> input;
if (input % 2 == 0)
{
cout << "Even!" << endl;
}
else
{
if (input% 2 == 1)
{
cout << "Odd" << endl;
cout << "Lets make it even shall we? " << "Your new number is... " << input + 1 << endl;
}
else if (isdigit(str[0]))
{
cout << "That isn't a number!" << endl;
}
}
system("pause");
return 0;
}
我遇到的问题是,如果用户输入的不是数字,它返回的值是“偶数”。
希望各位小伙伴们帮帮忙!约翰