【发布时间】:2015-07-25 09:00:45
【问题描述】:
我正在开发一个程序,提示用户输入参加比赛的参赛者的姓名和评委给出的分数。所有这些都在一个带有计数器的 for 循环中,以跟踪参赛者的数量。由于参赛者人数未知,用户应该输入“完成”退出循环。
我发现退出循环的所有方法都是使用布尔值,它不适用于“字符串”变量。 我想知道是否有办法通过输入“完成”这个词来退出循环
#include <iostream>
#include <string> //for name entry of contestants
#include <iomanip> //rounding and point perceision
#include <fstream> //write names and averages to a file for storage
using namespace std;
double calcAvgScore(int, int, int, int, int); //calculates the average after the highest and lowest scores are found
double findHighest(int, int, int, int, int); //finds the highest of the 5 scores
double findLowest(int, int, int, int, int); //finds the lowest of the 5 scores
int main()
{
string cName; //name of the contestant
int jScore1, jScore2, jScore3, jScore4, jScore5; //scores of each judge
double AvgScore; //average of the scores
ofstream outFile;
outFile.open("NamesAndAverage.txt");
for (int count = 1;; count++)
{
if (count = 1)
cout << "Please enter the name of Contestant #" << count << ". If there are no Contestants enter ""Done""";
else
cout << "Please enter the name of Contestant #" << count << ". If there are no more Contestants please enter ""Done""";
cin >> cName;
}
}
【问题讨论】:
-
您在寻找
break;吗?
标签: c++ loops for-loop exit break