C中的简单兴趣计算程序总是返回0作为结果

Bib*_*ist 0 c

我试过Turbo C和Borland C.没有区别.该计划如下:

#include<stdio.h>
#include<conio.h>

int main()
{
    int c,y;
    float r,si;
    printf("Enter the value of c,y,r");
    scanf("%d%d%f",&c,&y,&r);
    si=c*y*r/100;
    printf("%f\n",si);
    getch();
}
Run Code Online (Sandbox Code Playgroud)

当我编译并运行它时,无论我选择什么值,答案总是为0.快速回复将受到高度赞赏.

小智 8

我刚用g ++运行你的程序.我认为你的输入错误.

arvvvs@UHome-K53E:~/Documents/StackOverflowHelp$ ./interest 
Enter the value of c,y,r1 2 3
0.060000
arvvvs@UHome-K53E:~/Documents/StackOverflowHelp$ ./interest 
Enter the value of c,y,r1, 2, 3
0.000000
Run Code Online (Sandbox Code Playgroud)

(我确实删除了conio.h和getch行.)

如果您想使用逗号输入,请从以下位置更改:

scanf("%d%d%f",&c,&y,&r);
Run Code Online (Sandbox Code Playgroud)

至:

scanf("%d, %d, %f",&c,&y,&r);
Run Code Online (Sandbox Code Playgroud)

(或者,更好的是,测试返回值scanf()是否为3.如果不是,则存在数据输入问题.)