- #1
cworrier
- 3
- 0
I've been trying for days to get my boyfriend's C++ program to work, and I am almost ready to concede defeat, but I have frequented this site in the past as a lurker, actually learning a lot of what I know from the tutorials (thanks!).
Now, I have a problem I just can't seem to solve.
The object is to have the user pick a choose from a menu and have that value stored somewhere to be used by a function later. Once that choice is picked, the user needs to be able to pick another choice, until he or she fills in all three choices and then it's on to the formula! I also need a choice for clearing the data (I know how to set it all to 0) and one for quitting the program (just return 0; right?), as well as a display of the data that has been entered already once the formula calculates (I have this block of code written too). My formula works, but I'm not sure how to get all the values stored or how to let the user go back and pick a choice from the list after he or she has chosen one already.
Here's what I have so far, and it's a work in progress, but hopefully it's on the right track. I'm thinking I need to, maybe, use a switch statement for the menu, but I can't get that to work for me, and I'm still not sure how to store a value that's not going to be immediately used (maybe something with an array, but again I seem unable to produce the right code).
Now, I have a problem I just can't seem to solve.
The object is to have the user pick a choose from a menu and have that value stored somewhere to be used by a function later. Once that choice is picked, the user needs to be able to pick another choice, until he or she fills in all three choices and then it's on to the formula! I also need a choice for clearing the data (I know how to set it all to 0) and one for quitting the program (just return 0; right?), as well as a display of the data that has been entered already once the formula calculates (I have this block of code written too). My formula works, but I'm not sure how to get all the values stored or how to let the user go back and pick a choice from the list after he or she has chosen one already.
Here's what I have so far, and it's a work in progress, but hopefully it's on the right track. I'm thinking I need to, maybe, use a switch statement for the menu, but I can't get that to work for me, and I'm still not sure how to store a value that's not going to be immediately used (maybe something with an array, but again I seem unable to produce the right 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;
cout << " \n";
cout << "Enter a Loan Amount: $";
cin >> a;
cout << "Enter a Loan Rate: ";
cin >> b;
cout << "Enter a Term in Years: ";
cin >> c;
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;
return0;
}