【发布时间】:2014-11-10 23:12:39
【问题描述】:
我已经在这里工作了好几个小时,但我希望能够添加另一个潜水员,我唯一需要展示的是被评判的潜水员数量和他们的平均分数,一旦这个问题我可以做是固定的。
它运行,但是当它循环时,它会跳过城市,并最终在第二到第三次崩溃。 有人可以帮忙吗?
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
string name;
string city;
double judge[4];
double total = 0;
double score;
int divers = 1;
int x = 0;
int y = 1;
do{
cout << "Please enter divers name: ";
getline(cin, name);
cout << "Enter the diver's city: ";
getline(cin, city);
do{
cout << "Enter the score given by judge #" << y << ": " ;
cin >> judge[x];
total = total + judge[x];
y++;
x++;
} while(y < 6);
y = 1;
cout << "Divers?";
cin >> divers;
} while(divers == 1);
cout << city << endl;
cout << name << endl;
cout << total << endl;
cout << judge[0] << endl;
cout << judge[1] << endl;
cout << judge[2] << endl;
cout << judge[3] << endl;
cout << judge[4] << endl;
system("PAUSE");
}
【问题讨论】:
-
您想添加潜水员,而您的代码只接受一个潜水员 (while(divers == 1))....while(condition is not true) 是 do-while 循环的工作方式。这有帮助吗?
-
请不要通过破坏您的帖子为他人增加工作量。通过在 Stack Exchange (SE) 网络上发帖,您已根据 CC BY-SA license 授予 SE 分发内容的不可撤销权利(即无论您未来的选择如何)。根据 SE 政策,分发非破坏版本。因此,任何破坏行为都将被撤销。请参阅:How does deleting work? …。如果允许删除,则帖子下方左侧有一个“删除”按钮,但仅在浏览器中,而不是移动应用程序中。
标签: c++ string loops while-loop