gpt4 book ai didi

c - 利率计划

转载 作者:行者123 更新时间:2023-11-30 21:01:06 24 4
gpt4 key购买 nike

我刚刚开始学习 C。所以为了练习,我决定编写一个利率计算器,但由于某种原因,我的计算结果总是为 0,我无法弄清楚。如果可以的话请看一下。

#include <stdio.h>


main()
{


int time;
float principle, rate, total;

printf("What is your starting amount? ");
scanf(" %f", &principle);
printf("What is your interest rate? ");
scanf(" %f", &rate);
printf("How long do you want to save? ");
scanf(" %d", &time);

total = principle * rate * time;
printf("You will have earned an interest amount of $%d", total);
return 0;
}

最佳答案

printf("You will have earned an interest amount of $%d", total);

由于 total 是 float ,因此 %d 应为 %f。另外,在每行末尾添加一个新行也是一个很好的做法。

printf("You will have earned an interest amount of $%f\n", total);

关于c - 利率计划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36923660/

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