我正在尝试在变量“media”中添加变量“height”。但我没有成功。在IF内部,代码只保存一个变量。我的目标是scaf身高年龄和体重,以及接下来40岁以下人群的身高平均值。
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
int age[20],height[20],weight[20],contidade=0,media=0,peso1=0;
for (int i = 0; i<4 ; i++){
cout << "type height age and weight: ";
cin >> age[i];
cin >> height[i];
cin >> weight[i];
if (age[i] > 50){
contidade++;
}
if (10 < age[i] && age[i] < 20){
media = media + height[í]; //error is here.
}
if (weight[i] < 40){
peso1++;
}
}
cout << "number of people over 50 years.: " << contidade << endl;
media = media/4;
cout << "Media height of people between 10 and 20 years: " << media << endl;
peso1 = peso1*100/4;
cout << "the percentage of people under 40 kg: " << peso1 << endl;
return 0;
}
答案 0 :(得分:1)
也许你的意思是编译错误:
media = media + height[í]; // wrong character
代替:
media = media + height[i];