<分区>
到目前为止,这是我的代码
int main()
{
srand(time(0));
int inputnum,occurrences;
occurrences = 0;
cout<<"Enter a number to check the occurences"<<endl;
cin>>inputnum;
int arrayofnum[10] = {(rand()%201),(rand()%201),(rand()%201),(rand()%201),(rand()%201),(rand()%201),(rand()%201),(rand()%201),(rand()%201),(rand()%201)} ;
cout<<arrayofnum[0]<<","<<arrayofnum[1]<<","<<arrayofnum[2]<<","<<arrayofnum[3]<<","<<arrayofnum[4]<<","<<arrayofnum[5]<<","<<arrayofnum[6]<<","<<arrayofnum[7]<<","<<arrayofnum[8]<<","<<arrayofnum[9]<<endl;
for(int i=1;i<=10;i++)
{
if(inputnum == arrayofnum[i])
occurrences++;
}
cout<<"The number of occurrences of "<<inputnum<<"in the random list is "<<occurrences<<" times"<<endl;
system("pause");
return 0;
}
我的目标是检查输入的数字在数组中显示了多少次 但是 if 语句似乎给我带来了麻烦有人可以帮忙吗?