Using the switch statement,write a menu driven program to calculate the maturity amount of a bank deposit The user is given the following options:1)Term deposit 2)Recurring deposit.For option1)accept principle(P),rare of intrest (r) and Tim period in years (n).Calculate and display receivable maturity amount(A) using the formula:A=p (1+r/100)to power n.For option 2)accept monthly instalment(p),rate of intrest (r) and time period in months(n).Calculate and display the receivable maturity amount(A) using formula:A=pn+(n (n+1)/2)×r/100×1/12.For an incorrect options an appropriate errors message should be displayed.
Answers
#include<iostream>
#include <math.h>
using namespace std;
int main()
{
int ch;
float A , P , r , n;
cout<<"Press 1 for Term deposit \nPress 2 for Recurring deposit \nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter Principle : ";
cin>>P;
cout<<"Enter Rate of Interest : ";
cin>>r;
cout<<"Enter Time Period in years : ";
cin>>n;
A=P * pow((1 + r / 100.0),n);
cout<<"Maturity Amount : "<<A;
break;
case 2:
cout<<"E n t e r M o n t h l y I n s t a l m e n t : ";
cin>>P;
cout<<"Enter Rate of Interest : ";
cin>>r;
cout<<"Enter Time Period in months : ";
cin>>n;
A = P * n + (n * (n + 1) / 2.0) * r / 100.0 * 1.0 / 12.0;
cout<<"Maturity Amount : "<<A;
break;
default :
cout<<"Incorrect Option";
}
return 0;
}