我试图让用户输入一个号码,然后仔细检查他们是否已输入该特定号码。我想用一个计数器将用户输入的数字存储在数组中,然后用for循环控制的计数器检查相同的数组就可以了,但是当我在数组元素中使用for循环计数器时,它似乎总是为零。有人能指出我在正确的方向吗?我无法弄清楚我做错了什么。
#include <iostream>
using namespace std;
int main() {
int guess[101] = { 0 };
int count = 0;
int check = 0;
while (guess[count] != 1) {
count++;
cout << "Enter an integer." << endl;
cin >> guess[count];
if (guess[count] == 0) {
return 0;
}
for (check = 0; check < count; check++) {
cout << guess[check] << endl;
if (guess[count] = guess[check]) {
cout << "You already guessed " << guess[check] << ". Try a different integer between 1 and 100.\n" << endl;
}
}
}
}
答案 0 :(得分:0)
if(guess [count] == guess [check])double等于应该用于比较。