0 未満または 18 を超える値を入力した場合、10 歳の学生の年齢をユーザーに尋ねようとしています。その値を 0 に変更します。
私は何を間違えましたか?
#include <iostream>
using namespace std;
int main()
int age [10];
int TotalAge, AverageAge;
for (int i = 0; i < 10; i++)
{
cout << "please enter the age of students:";
cin >> age[i];
if age[i] < 0 || age[i] >
cout << "An error was detected in your input, invalid age"; // print
age[i] = 0;
TotalAge += age[i]; // total age is the sum of age
AverageAge = TotalAge / 10;
cout << "Average age of class is: " << AverageAge << endl
}