我有无法工作的循环
它只显示第一个cout输入1个学生信息
或以太它跳过循环并在其下做所有事情
你能帮忙吗int x = 1;
while (x <= 10) {
++x;
if (x = 1) {
cout << "enter 1 student info";
cin >> name >> first >> second >> final>>id;
} else if (x = 2) {
cout << "enter 2 student info";
cin >> name1 >> first1 >> second1 >> final1 >> id1;
} else if (x = 3) {
cout << "enter 3 student info";
cin >> name2 >> first2 >> second2 >> final2 >> id2;
} else if (x = 4) {
cout << "enter 4 student info";
cin >> name3 >> first3 >> second3 >> final3 >> id3;
}
}
...
for (int x = 1; x <= 9; x++) {
if (x = 1) {
cout << "enter 1 student info";
cin >> name >> first >> second >> final>>id;
}
if (x = 2) {
cout << "enter 2 student info";
cin >> name1 >> first1 >> second1 >> final1 >> id1;
}
if (x = 3) {
cout << "enter 3 student info";
cin >> name2 >> first2 >> second2 >> final2 >> id2;
}
if (x = 4) {
cout << "enter 4 student info";
cin >> name3 >> first3 >> second3 >> final3 >> id3;
}
}
答案 0 :(得分:6)
如果您使用=
(赋值运算符)代替==
(等于运算符),我只会向您显示第一个错误
int x=1;
while (x<=10)
{++x;
if(x==1)
有关详细信息,请查看cpp参考或wikipidia