我刚刚开始学习c ++,这是我的代码:
#include <iostream>
using namespace std;
int main()
{
int a[5];
for(int i = 0 ; i < 5 ; i++)
{
cin >> a[i];
if (a[i] % 2 == 0)
{
cout << "the number" << a[i] << "is even" << endl;
}
if(a[i] % 2 != 0)
{
cout << "the number" << a[i] << "is odd" << endl;
}
}
}
[当我输入5个像(12345)这样的数字并进行构建时,它仅显示例如:(数字12345是偶数。我不明白为什么它不能正常工作。
请告诉我我的错误是什么。
字符串“ 12345”代表整数1,2,3,455。因此,当您使用常规整数规则读取该字符串时,即为您获得的整数。