私はここでうんざりしています。 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);
}
}
'私は教授の指示に従って配列やベクトルを使うことはできません。' 'double score [5]'のような単純な配列ではないのですか?それは過度に厳しいようです。 –
@Jesse欲しいです。私は指示に従ってこのプログラムを動作させましたが、バグのようなものがたくさんあります。 – Gmenfan83
配列を使用した[例](http://ideone.com/8v7IR)があります。 –