我知道我的程序是正确的,但是 netbeans 没有按照预期的方式操作它。我在 Android 移动 C 编译器应用程序上运行了相同的程序,并且运行良好。我是新来的,所以我无法插入照片来向您展示此处的输出,但请单击提供的链接以查看我的 netbeans 给我的输出。
请告诉我 IDE 有什么问题以及我该如何修复它。
下面是程序:
#include <stdio.h>
#include <math.h>
int main() {
int x = 1, q, n, p;
float r, b, a;
while (x <= 10) {
printf("enter the value of principle\n");
scanf("%d", &p);
printf("enter the number of years\n");
scanf("%d", &n);
printf("enter number of times interest is added\n");
scanf("%d", &q);
printf("enter rate of interest\n");
scanf("%d", &r);
b = pow((1 + r / q), n * q);
a = p * b;
printf("amount=%f\n", a);
x++;
}
return 0;
}
最佳答案
这只是一个非常小的错误。逻辑完全没问题。我认为您忽略了 rate of interest
的访问说明符的一小部分。 。您已正确且恰本地将其声明为 float
。但是,在接受用户的值时,您将使用 %d
将其作为整数接受。 。编译器没有预料到这一点,因此行为异常。只需将接受利率部分替换为:
`printf("enter rate of interest\n");
scanf("%f", &r);`
现在应该可以正常工作了。只需附上输出即可确定:
block 引用>gcc version 4.6.3
enter the value of principle 5000
enter the number of years 2
enter number of times interest is added 4
enter rate of interest 2.5
amount=243106.703125
enter the value of principle
是的,它按照您的
while
执行此操作 10 次循环。
关于c - 我的 C 程序无法在 NetBeans 上运行,但在 Android 移动 C 编译器应用程序上运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52364765/