my c-program doesn't work on NetBeans but works fine on android mobile c compiler app

104 Views Asked by At

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;
}

enter image description here enter image description here

1

There are 1 best solutions below

0
On

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 a float. 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:

   `printf("enter rate of interest\n");
    scanf("%f", &r);`

It should work fine now. Just attaching the output for you to be sure of it:

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

and yes, it does this 10 times as per your while loop.