# Answer to Question #44644 in C++ for shivam chawla

Question #44644

Write a menu driven program in C++ to calculate the simple interest or compound interest depending

upon the user’s choice. Write and use functions to calculate simple interest and compound interest.

upon the user’s choice. Write and use functions to calculate simple interest and compound interest.

Expert's answer

`#include <iostream>`

using namespace std;

int main()

{

//global variables

int ch=-1;

double P;

double j;

int m;

int t;

double S;

double SI;

do{

while(ch<1 || ch>3){

//show menu

cout<<"1 - Simple interest\n";

cout<<"2 - Compound interest\n";

cout<<"3 - Exit\n";

cout<<"Your choice: ";

cin>>ch;

switch(ch){

case 1:

//Principal or Sum [P] =

cout<<"Enter principal amount: ";

cin>>P;

//Rate % per Annum [j] = %

cout<<"Enter interest rate: ";

cin>>j;

//Time [T] =

cout<<"Enter time: ";

cin>>t;

//Simple Interest [S.I.]

SI=(P*j*t)/100;

//show result

cout<<"Simple Interest: "<<SI<<"\n\n";

break;

case 2:

//P = principal amount (initial investment)

cout<<"Enter principal amount: ";

cin>>P;

//j = annual nominal interest rate (not reflecting the compounding)

cout<<"Enter an annual nominal interest rate: ";

cin>>j;

//m = number of times the interest is compounded per year

cout<<"Enter the number of times the interest is compounded per year: ";

cin>>m;

//t = number of years the money is borrowed for

cout<<"Enter the number of years the money is borrowed for: ";

cin>>t;

//S = value after t periods

S=P*pow((1+j/m),m*t);

//show result

cout<<"Future Value: $"<<S<<"\n\n";

break;

case 3:

break;

}

}

}while(ch!=3);

return 0;

}

## Comments

## Leave a comment