好吧,我有点难倒在这里。我不知道如何操作我的代码来执行while loop
。这里是代码块(我不能使用每个教授指令的数组或向量)。感谢任何想法提前。输入验证方法?
//function prompts the user for test scores, validates and stores the input scores
void getScore(double &score1, double &score2, double &score3, double &score4, double &score5)
{
cout << "Enter a score: ";
//input validation
while(score1 < 0 || score1 > 100 || score2 < 0 || score2 > 100 || score3 < 0 || score3 > 100 || score4 < 0 || score4 > 100 || score5 < 0 || score5 > 100)
{
cout << "Invalid input, all values\n";
cout << "must be between 0 and 100\n";
cin >> score1;
cout << "Enter a score: ";
cin >> score2;
cout << "Enter a score: ";
cin >> score3;
cout << "Enter a score: ";
cin >> score4;
cout << "Enter a score: ";
cin >> score5;
cout << "------------------------" << endl;
}
if(!(cin >> score >> score2 >> score3 >> score4 >> score5))
{
cout << "You have entered\n";
cout << "non-numeric input.\n";
cout << "Program is terminated\n";
cout << "Please try again" << endl;
exit(0);
}
}
'我不能使用数组或矢量每个教授指令'甚至没有一个简单的数组,如'双分[5]'?这似乎过于严格。 – 2012-02-20 04:06:19
@Jesse我希望。我有这个程序按照说明工作,但有这么多的事情,使我感到烦恼。 – Gmenfan83 2012-02-20 04:20:27
这里是[一个例子](http://ideone.com/8v7IR)使用数组,可能会有所帮助。 – 2012-02-20 04:43:25