Write most basic C++ program possible that calculates monthly savings account balance. Program will prompt user to enter initial account balance, annual percentage rate, amount deposited each month, and total number of months. Validate user inputs allowing only positive numbers.
B = initial account balance
A = amount deposited each month
R = annual percentage rate
Total Balance = (R/12+1)B+A
#include <iostream>
using namespace std;
int main(){
double initial_account_balance,total_balance;
double annual_percentage_rate,monthly_interest;
double amount_deposited;
double number_of_months;
while(true){
cout<<"ENter positive initial account balance :";
cin>>initial_account_balance;
if(initial_account_balance>0)break;
}
while(true){
cout<<"ENter positive annual percentage rate :";
cin>>annual_percentage_rate;
if(annual_percentage_rate>0)break;
}
while(true){
cout<<"ENter positive amount deposited:";
cin>>amount_deposited;
if(amount_deposited>0)break;
}
while(true){
cout<<"ENter positive number of months :";
cin>>number_of_months;
if(number_of_months>0)break;
}
total_balance=initial_account_balance;
monthly_interest=annual_percentage_rate/12;
for(int i=1;i<=number_of_months;i++){
total_balance+=total_balance*monthly_interest;
}
cout<<total_balance<<endl;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.