I know my program is correct, but netbeans is not operating it the way it suppose to be. I ran the same program on android mobile c compiler app and it worked fine. I am new here so I cannot insert a photo to show you the output here, but please click the link provided to see the output my netbeans is giving me.
Please tell me what is wrong with my IDE and what can i do to fix it.
here is the program below:
#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;
}
this is just a very small error. The logic is totally fine. I think you overlooked just one tiny bit of an access specifier for the
rate of interest
. You have correctly and aptly declared it as afloat
. But while accepting the value from the user, you are accepting it as an Integer using%d
. The compiler doesn't expect this and hence behaves unusually. Just replace The accepting rate of interest part with this:It should work fine now. Just attaching the output for you to be sure of it:
and yes, it does this 10 times as per your
while
loop.