I've been working on my boyfriend's C++ program since last Sunday and I still can't get it right. I've tried a lot of different solutions and I just can't quite get over one big obstacle.
The problem is this--I need the program to offer the user a selection from a menu, but when I do, I can't get the menu to work again. It will display again, but the choices don't do anything. It's a generic mortgage calculator that I have done in several other languages, but being relatively new to C++, I just can't figure out what I'm doing wrong. My boyfriend, as of yet, has been very little help. I tutored him up until this point, but now I'm stumped too.
The version I'm working with now has a switch statement, because that seems to work best for menus, but I don't know how to bring it back to the menu. My boyfriend keeps insisting that there should be something with an array because that was what he's been studying. I'm not sure about that or how an array would accomplish what I need done.
Here is the code so far, and sorry it's so long.
CODE
#include <iostream>
#include <math.h>
using namespace std;
doublemortgage (int c, double b, double a)
{
int i = c;
double j = b;
double k = a;
double l = b/(12 * 100);
double m = c * 12;
double result = k * (l / (1 - pow(1+l, -m)));
return result;
}
int main ()
{
int c;
double b;
double a;
double result;
int x;
cout << "Mortgage Calculation Menu \n";
cout << "1. Enter a Loan Amount \n";
cout << "2. Enter a Loan Rate \n";
cout << "3. Enter a Term in Years \n";
cout << "4. Calculate a Payment \n";
cout << "5. Clear All Input \n";
cout << "9. Quit \n";
cout << "Enter Your Selection: ";
cin >> x;
switch(x)
{
case1: cout << "Enter a Loan Amount: $";
cin >> a;
break;
case2: cout << "Enter a Loan Rate: ";
cin >> b;
break;
case3: cout << "Enter a Term in Years: ";
cin >> c;
break;
case4: cout << "Your Monthly Payment: $"<< mortgage (c, b, a) << endl;
cout << " \n";
cout << "You Entered"<<endl;
cout << "Loan Amount: $"<<a<<endl;
cout << "Loan Rate: "<<b<<"%"<<endl;
cout << "Loan Term: "<<c<<"years"<<endl;
cout << "Monthly Payment: $"<< mortgage (c, b, a) << endl;
break;
case5: cout << "Data Cleared";
a = 0;
b = 0;
c = 0;
break;
case9: cout << "Quitting Program";
break;
default: cout << "Invalid Selection. Choose Another Option.";
break;
}
return0;
}