C++ Program for Compound Interest with Recursion
This C++ Program will help you to Calculate Compound Interest. You can use this online Compound Interest Calculator to calculate Compound Interest for the given value.//source code CompoundInterest.cpp
#include<iostream>
#include<cstdlib>
using namespace std;
float initialDeposit=0;
int depositMonth=0;
float interestRate=0;
float total=0;
void mainFunction();
void endingBalance();
bool goAgain();
int main() {
do{
system("cls");
mainFunction();
endingBalance();
}while(goAgain());
cin.get();
cin.get();
return 0;
}
void mainFunction(){
cout<<"Enter the initial deposit? ";
cin>>initialDeposit;
cout<<endl;
cout<<"How many months is the deposit? ";
cin>>depositMonth;
cout<<endl;
cout<<"Annual Interest rate? ";
cin>>interestRate;
cout<<endl;
}
void endingBalance(){
cout<<"With an initial deposit of $";cout<<initialDeposit;cout<<" and an interest rate of "; cout << interestRate; cout<<"% the balance at the end of ";cout<<depositMonth; cout<< " months is $"; cout<<total; cout<<".";
cout<<endl;
}
bool goAgain()
{
char answer;
cout << "Would you like to go again?";
cin >> answer;
while(answer != 'y' && answer != 'Y' && answer != 'n' && answer != 'N')
{
cout << "Invalid choice. Would you like to go again?";
cin >> answer;
}
cout << endl;
if(answer == 'y' || answer == 'Y')
return true;
else
return false;
}
