添加花车并存储它们, [英] adding floats and storing them,

查看:73
本文介绍了添加花车并存储它们,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是C ++的入门者,我想知道如何添加和存储浮点数,例如:

Hi,
I''m a begginer with C++ I was wondering how I would add and store floats for example:

int main(int argc, char *argv[])
{
    float height;
    float length;
    float total;

    cout << "Please enter height: ";
    cin >> height;
    cout << "Please enter length: ";
    cin >> length;

// this is the bit I don''t understand

    height*length = total; ?

// how do I store the input as a new float?

    
    system("PAUSE");
    return EXIT_SUCCESS;
}

推荐答案

C ++就像几乎每种编程语言一样,都要求您声明目的地,然后为其分配一个值,如下所示:

total = height * length;

您的教科书应该已经清楚了这一点.
C++, like almost(?) every programming language, requires that you declare your destination and then assign it a value, like this:

total = height * length;

Your textbook should have made this clear.


尝试其他方法:destination = source;
Try going the other way: destination = source;
total = height*length;

您已经创建了一个新的浮点存储结果,称为总计".您只需要用另一种方法来做!

You have already created a new float top store the result in, called "total". You just need to do it the other way round!


您只需要反转您编写的公式即可:
这是正确的方法:

you just have to invert the formula that you wrote:
this is the correct way:

total=height*length;



因此,这里发生的是,高度和长度的值相乘,然后分配给total或存储在float变量total中.您上面写的内容会给您一个错误,因为它希望左侧的变量被分配一个值.
因此,您要总计存储值,那么正确的方法就是我上面写的方法.



so what happens here is that, the height and length''s value is multiplied and then is assigned to total or stored in the float variable total. What you wrote above will give you an error because it expects a variable at the left side to be assigned a value.
So you want to store the value in total so the correct way is the one i wrote above.


这篇关于添加花车并存储它们,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆