2015-11-06 41 views
0

我试图在变量“media”中添加变量“height”。但我没有成功。在IF中,代码只保存一个变量。我的目标是scaf身高和体重,以及下一个40岁以下人的身高平均值。我试图在变量“media”中添加变量“height”

#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];