我试图询问 10 岁学生的用户是否输入小于 0 或大于 18 的任何内容,我希望它将该值更改为 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
}