【发布时间】:2015-12-07 04:45:42
【问题描述】:
这应该是用户在数组中输入整数然后调用显示它们是偶数还是奇数的函数的代码。然后它计算有多少是偶数或奇数(我还没有得到,因为我被困在这里并且我不断收到这个错误)。
“int [20]”和“int”类型的无效操作数到二进制“operator%”
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
void getValue(int[], int);//function prototype
int main()
{
const int ARRAY_SIZE = 20;
int numbers[ARRAY_SIZE];
cout<<fixed<<showpoint<<setprecision(1);
//get ints from user
getValue(numbers, ARRAY_SIZE);
if ( numbers % 2== 0 )
// if the integer when divided by 2 has no remainder then it's even.
cout << numbers << " is even "<<endl;
else
// the integer is odd
cout << numbers << " is odd "<<endl;
return 0;
}
void getValue(int numbers[], int ARRAY_SIZE)
{
//loop counter
int index;
//get each value
for(index = 0; index <= ARRAY_SIZE - 1; index++)
{
cout<< "Enter an integer " << (index + 1)<< " : ";
cin>> numbers[index];
}
}
【问题讨论】:
-
那么如果用户提供“3 4 5”,程序应该打印什么?