I have a school project for a simple program that is supposed to give interest rates based on loan amounts, but the code has a problem. Plz someone help
#include <iostream>
using namespace std;
int main ()
{
int l;
int t;
int a;
int p;
int i;
int m;
int x;
cout<<"This are the different loan types"<<endl;
cout<<"1: Home loan"<<endl;
cout<<"2: Car loan"<<endl;
cout<<"3: Business loan"<<endl;
cout<<"What loan type do you want?"<<endl;
cin>>l;
switch (l)
{
case 1:
cout<<"You selected a home loan"<<endl;
break;
case 2:
cout<<"You selected a Car loan"<<endl;
break;
case 3:
cout<<"You selected a Business Loan"<<endl;
break;
default:
cout<<"Error"<<endl;
}
cout<<"There are two account types"<<endl;
cout<<"1: Salary account"<<endl;
cout<<"2: Fixed account"<<endl;
cout<<"What is your account type?"<<endl;
cin>>t;
switch (t){
case 1:
cout<<"You have a salary account"<<endl;
cout<<"Salary accounts have a flat interest rate of 12%"<<endl;
cout<<"Please Enter loan amount"<<endl;
cin>>a;
i = (0.12 * a);
cout<<"The interest payable is, "<<i<<endl;
x = (i + a);
cout<<"The total amount payable is, "<<x<<endl;
cout<<"How many months do you wish to take to repay?"<<endl;
cout<<"The allowable period is between 6 months and 60 months"<<endl;
cin>>p;
m = (x / p);
cout<<"You are required to pay "<<m<<" every month"<<endl;
break;
case 2:
cout<<"You have a Fixed account"<<endl;
cout<<"Please enter the amount"<<endl;
cin>>a;
if (a<100000)
i = (0.13 * a);
cout<<"The Interest payable is, "<<i<<endl;
x = (i + a);
cout<<"The total amount payable is, "<<x<<endl;
cout<<"How many months do you wish to take to repay?"<<endl;
cout<<"The period is between 6 months and 60 months"<<endl;
cin>>p;
m = (x / p);
cout<<"You are required to pay "<<m<<" every month"<<endl;
if (a<200000)
i = (0.125 * a);
cout<<"The Interest payable is, "<<i<<endl;
x = (i + a);
cout<<"The total amount payable is, "<<x<<endl;
cout<<"How many months do you wish to take to repay?"<<endl;
cout<<"The period is between 6 months and 60 months"<<endl;
cin>>p;
m = (x / p);
cout<<"You are required to pay "<<m<<" every month"<<endl;
if (a<500000)
i = (0.11 * a);
cout<<"The interest payable is, "<<i<<endl;
x = (i + a);
cout<<"The total amount payable is, "<<x<<endl;
cout<<"How many months do you wish to take to repay?"<<endl;
cout<<"The period is between 6 months and 60 months"<<endl;
cin>>p;
m = (x / p);
cout<<"You are required to pay "<<m<<" every month"<<endl;
if (a<1000000)
i = (0.10 * a);
cout<<"The interest payable is, "<<i<<endl;
x = (i + a);
cout<<"The total amount payable is, "<<x<<endl;
cout<<"How many months do you wish to take to repay?"<<endl;
cout<<"The period is between 6 months and 60 months"<<endl;
cin>>p;
m = (x / p);
cout<<"You are required to pay "<<m<<" every month"<<endl;
else
i = (0.09 * a);
cout<<"The interest payable is, "<<i<<endl;
x = (i + a);
cout<<"The total amount payable is, "<<x<<endl;
cout<<"How many months do you wish to take to repay?"<<endl;
cout<<"The period is between 6 months and 60 months"<<endl;
cin>>p;
m = (x / p);
cout<<"You are required to pay "<<m<<" every month"<<endl;
break;
default:
cout<<"Error"<<endl;
}
Also you have a lot of duplicate code, read up on functions. They would make this program a number of times smaller and much easier to debug. http://cplusplus.com/doc/tutorial/functions