gpt4 book ai didi

c++ - 关于四舍五入和产生正确输入的代码帮助

转载 作者:行者123 更新时间:2023-11-28 06:52:10 26 4
gpt4 key购买 nike

<分区>

问题:

Your task is to:

Write a function that prints to the standard output (stdout) the number of users who didn't leave the site after 10 seconds (i.e: the number of users who didn't bounce).

Please round the result downwards to the nearest integer (e.g both 7.1 and 7.9 are rounded to 7).

Note that your function will receive the following arguments:

n which is an integer representing the number of visitors

b which is an integer representing the bounce rate (i.e: the percentage of users who left the site in the first 10 seconds)

我的代码编译得很好,我很确定我的逻辑是正确的,但我的输出是错误的,我不知道为什么。当 n = 1000b = 25 时,我的结果应该是 750。我不断获得 1000。我哪里错了?

我也不确定如何按照他们希望我的方式“舍入”。这也可能是我没有得到正确输出的原因吗?

我的代码:

void compute_active_users(int n, int b) {

int BounceConvert = (b / 100); //converts the value of b to a decimal
int BounceRate = (n * BounceConvert); // multiplys n times the b decimal
int TotalVisitors = (n - BounceRate); // subtract BounceRate

printf("%d", TotalVisitors); // print out the final result

}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com