Hey guys, I seem to have a slight calculation error and I need to know if it is an issue with the compiler or a mistake that I made.
With an initial investment of $1000 gaining 8% interest for 10 years the final output I get is $2158.93 ($2158.925049). However, using my TI-84 calculator I get $2158.92 ($2158.924997).
Is there a way to fix these little errors? I have noticed miscalculations like this in a few other programs, of course all of which have been very small like the error above.
Looking forward to the advice! Thank you!
Code:
#include <stdio.h>
#include <math.h>
int main()
{
float a, r, x; int n; // variables
// asking for the initial deposit
printf("What is the initial deposit?"); fflush(stdout);
scanf("%f", &x);
// asking for the length of time
printf("For how many years will your money be invested?"); fflush(stdout);
scanf("%d", &n);
// asking for the annual rate of return
printf("What is your expected annual rate of return?"); fflush(stdout);
scanf("%f", &r);
//calculating the total amount after n years
a = x * pow(1 + r/100,n);
printf("After %d years your initial investment of $%.2f will be worth $%.2f.", n, x, a);
return 0;
}