c++ - 我试图在变量 "height"中添加变量 "media"

标签 c++

我正在尝试在变量“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/

相关文章:

c++ - 如何将二维数组相互分配?

c++ - 如何在 C++ 中存储 128 位数字?

c++ - 在 C++ 中重载子类中的方法

c++ - 如何找到满足 GCD(a,b) = x 的 a,b<N 对数?

C++源码帮助,cout函数帮助

C++ - 对象何时销毁

c++ - 使用模板元编程实现 std::all_of 的静态版本?

c++ - 在 Qt 中的两个类之间发出信号

c++ - 关于访问 %gs

c++ - 销毁 gtkmm 消息对话框?