gpt4 book ai didi

c - 分数报告问题

转载 作者:行者123 更新时间:2023-11-30 20:29:23 24 4
gpt4 key购买 nike

你们能帮我做一个简单的报告计算吗

第一分 x 20%

第二次得分 x 40%

第三次得分 x 40%

示例:

输入:

65 56 100

输出:

75.00

我的代码:

#include <stdio.h>
#include <math.h>

int main() {

int score1, score2, score3;
float amount;
float n;

float percent1 = 0.2;
float percent2 = 0.4;
float percent3 = 0.4;
scanf("%f %f %f",&n, &n, &n);

score1 = (float)n*percent1;
score2 = (float)n*percent2;
score3 = (float)n*percent3;

amount = score1+score2+score3;
printf("%.2f\n", amount);

getchar();
return 0;
}

我的输入:

65 56 100

我的输出:

100.00

你可以在那里看到它,输出一定是92.00

有什么错误吗?

请帮助我,你

最佳答案

您对所有三个输入值使用相同的变量 (n)。每个输入值都需要一个单独的变量。使用 score 变量存储值,然后在单个计算中使用它们。

#include <stdio.h>
#include <math.h>

int main()
{
int score1, score2, score3;
float amount;
/* Variable 'n' not required, since not used. */
float n;

float percent1 = 0.2;
float percent2 = 0.4;
float percent3 = 0.4;

scanf("%f %f %f",&score1, &score2, &score3);

amount = (score1 * percent1) + (score2 * percent2) + (score3 * percent3);
printf("%.2f\n", amount);

getchar();
return 0;
}

关于c - 分数报告问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58262267/

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