Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        3年前关闭。
                                                                                            
                
        
我刚刚开始学习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是浮点型,因此%d应该是%f。另外,在每行的末尾添加新行也是一种不错的感觉。

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

10-08 15:06