write a program that uses a for loop to calculate the balanc

write a program that uses a for loop to calculate the balance in a savings account. The program should accept a deposit and interest rate from the user, then calculate and print for each of the next 10 years the interest earned and the balance at the end of the year. Output the year, interest, and balance in table format. Use posttest loops to put and error trap around the deposit to make sure it is greater than 0 and around the interest rate to make sure it is greater than 0 and no more than 100%. Test your program $1000 and 10%, then $3500 and 6%.

Solution

#include <stdio.h>

int main(void) {
   int deposit=0,interest=0,ans=0,balance=0,i=0;
   printf(\"Enter deposit and interest:\ \");
   scanf(\"%d%d\",&deposit,&interest);
   balance=deposit;
   for(i=1;i<=10;i++)
   {
   ans=(deposit)*(i)*(interest);
   ans=ans/100;
   balance=balance+ans;
   printf(\"year %d\ \",i);
   printf(\"Interest earned: %d\\t\",ans);
   printf(\"Balance:%d\ \",balance);
  
   }
   return 0;
}

Input: 1000 10

Output: Enter deposit and interest:
year 1
Interest earned: 100   Balance:1100
year 2
Interest earned: 200   Balance:1300
year 3
Interest earned: 300   Balance:1600
year 4
Interest earned: 400   Balance:2000
year 5
Interest earned: 500   Balance:2500
year 6
Interest earned: 600   Balance:3100
year 7
Interest earned: 700   Balance:3800
year 8
Interest earned: 800   Balance:4600
year 9
Interest earned: 900   Balance:5500
year 10
Interest earned: 1000   Balance:6500

write a program that uses a for loop to calculate the balance in a savings account. The program should accept a deposit and interest rate from the user, then ca

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site