利率计划

时间:2016-04-28 19:19:00

标签: c

我刚刚开始学习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;
}

1 个答案:

答案 0 :(得分:1)

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

由于total是浮点数,%d应为%f。此外,在每一行的末尾抛出一个新行是一个不错的选择。

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