我正在尝试在变量“media”中添加变量“height”。但我没有成功。在 IF 代码中只保存一个变量。我的目标是高度、年龄和体重,以及 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;
}
最佳答案
也许你的意思是编译错误:
media = media + height[í]; // wrong character
替换为:
media = media + height[i];
关于c++ - 我试图在变量 "height"中添加变量 "media",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33569150/