c++ 有人能告诉我这个代码有什么问题吗?[关闭]

ruarlubt  于 2023-03-25  发布在  其他
关注(0)|答案(1)|浏览(139)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
22小时前关门了。
Improve this question
我不断geeting 0作为输出,虽然代码写得正确,有人知道这个问题吗?我应该得到折扣后的价格,买不知何故我不断得到0广告输出.下面是代码:

#include <iostream>
using namespace std;
int main() {
    int ages[5];
    int sum = 0;
    for (int i = 0; i < 5; i++) {
        cin>>ages[i];
    }
    //your code goes here
    int youn = ages[0];
    for(int i = 0; i < 5; i++){

        
         if(ages[i] < youn){
            youn = ages[i];
        } 
        sum += 10;
    }
    int discount = (youn/100)*sum;
    sum -= discount;
    cout<<sum;
    return 0;
}

nhhxz33t

nhhxz33t1#

(youn/100)*sum是整数除以100,如果youn小于100,结果将为0。您可以添加100。就像πάντα ε说的那样,或者您可以将youn定义为float并像这样分配它

float youn = ages[0]*1.0f;

相关问题