为什么这个计算的结果总是等于零?

问题描述 投票:-3回答:1
int effectiveness()
{
    cout << "Let me check your effectiveness." << endl;

    result = scored / throws;

    real_result = result * 100;

    cout << "It is around " << real_result << " percent." << endl;

    return 0;
}

这是我担心的代码,您能告诉我为什么无论我输入什么,real_result总是等于零吗?

c++ calculation multiplying
1个回答
0
投票

检查您的物品类型。如果您的变量结果int,则无法获得浮点值:

int result;
result = 3/5;  //result will egal to zero
result = 3.1/5; //result will egal to zero
© www.soinside.com 2019 - 2024. All rights reserved.