Mr. James wanted to calculate his interest at the Bank of Sierra Leone, with a specific amount deposited, Time and Rate. Write C++ console program of functions to calculate the interest of Mr. James. The console application should asked the user to input values of Time, Rate and Amount deposited.
#include <iostream>
using namespace std;
float calculateInterest(int time, float rate,float amountDeposited);
int main (){
int time=-1;
float rate=-1;
float amountDeposited=-1;
while(time<=0){
cout<<"Enter time period of the deposit in years: ";
cin>>time;
}
while(rate<=0 || rate>100){
cout<<"Enter rate of interest [1-100%]: ";
cin>>rate;
}
while(amountDeposited<=0){
cout<<"Enter amount deposited: ";
cin>>amountDeposited;
}
float interest= calculateInterest(time,rate,amountDeposited);
cout<<"\nInterest: "<<interest<<"\n\n";
system("pause");
return 0;
}
//Calculates interest
float calculateInterest(int time, float rate,float amountDeposited){
return (time*rate*amountDeposited)/100.0;
}
Comments
Leave a comment