#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
// ** Monthly Payment ** //
{
system ("color f5");
string ans,name;
int menu;
double loan;
double intRate;
double month;
double LoanPayment;
cout <<" This program is to calculate the monthly payments"
<< endl << " of a Loan";
cout << "\n\n" << endl;
cout << "-- MENU --" << endl;
do
{
cout << "[1] - Exit" << endl;
cout << "[2] - calculate the monthly payment of a loan" << endl;
cout << "[3] - find out if you qualify for a loan" << endl;
cout << "Option: ";
cin >> menu;
if ( menu == 2)
{
cout << " Enter the Amount: ";
cin >> loan; // I entered 100,000
cout << " Enter percentage of interest: ";
cin >> intRate; // 5 percent
cout << " Enter the number of months: ";
cin >> month; // 12 months
LoanPayment=(loan*intRate/1200)/(1-pow((1+intRate),-month));
cout << " The monthly loan is: " << LoanPayment << endl; // it gives me 416.667 when it should give me 8560.74
}
elseif (menu == 3 )
{
cout << " Enter the amount that you are going to pay monthly ";
cout << " Enter loan interest";
cout << " Enter the number of months you're going to pay :";
cout << " loan amount is: ";
}
elseif( menu == 1)
{
cout << "Invalid Opcion.Please Select 1,2,3";
cout << "\n" << endl;
}
else
{
cout << " Are you sure you want to exit the program (y/n) : " ;
cin >> ans;
cout << endl;
}
} while (ans != "y" && ans != "Y");
return 0;
}
What is your problem? Does it compile - if not post the compilation errors in full. If it does, then try using the debugger.
I personally hate dislike constructs like what you have on line 79 & do loops (not a big fan of them either).
They are just ugly & not scalable.
You can make use of the toupper function, so you don't have to make 2 tests of the variable.
IMO, a better way is to have a while loop controlled by a bool:
1 2 3 4 5 6
bool Quit = false;
while (!Quit) {
//user wants to quit
Quit = true;
}
The menu should be processed with a switch inside the loop shown above. Always include a default case and remember to put a break statement after each case.