I wrote this program that displays the balance with interest after the number of years requested. When I run the program and say enter 75.00 for the "dollar amount deposited", the program skips over the input for interest and goes right to the input for years. If I enter "75" for the "dollar amount deposited", it will go to the input line for interest. Also, both scenerios produce wrong results. What did I do wrong? Here is my code:
Code:
/*
Filename: balance.c
Description: Displays the balance with interest compounnded annually,
after number of years entered.
*/
# include <stdio.h>
# include <math.h>
void introduction (void);
double ComputeBalance (double a, double r, int n);
int main()
{
/*Allocate memory for data*/
introduction ();
double a,r;
int n;
/*Prompt user for data*/
printf ("\nEnter the the dollar amount deposited: $");
scanf ("%.2lf",&a);
printf ("\nEnter the interest rate:");
scanf ("%lf",&r);
printf ("\nEnter the number of years:");
scanf ("%d",&n);
/*Processing and display results*/
printf ("\nYour balance after %d years with an\n");
printf ("interest rate of %lf would be");
printf (" $%.2lf\n",n,ComputeBalance(a,r,n));
return 0;
}
void introduction (void)
{
printf ("\nThis program displays the balance with interest,\n");
printf ("compounded annually after number of years entered.\n");
}
double ComputeBalance(double a,double r, int n)
{
return a*1+pow(r,n);
}