gpt4 book ai didi

c++ - 数组 :/有问题

转载 作者:行者123 更新时间:2023-11-28 07:15:13 25 4
gpt4 key购买 nike

<分区>

到目前为止,这是我的代码

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 语句似乎给我带来了麻烦有人可以帮忙吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com