我想要問10歲的學生的用戶,如果他們輸入小於0或超過18的任何東西,我希望它將該值更改爲0.C++,我做錯了什麼?
我做錯了什麼?
#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
}
我錯過了18 - 如果年齡[I] <0 ||年齡[i]> 18 –
在尋求幫助時,除了想要發生的事情外,還要描述實際發生的事情(包括任何錯誤消息)。 – outis