# Can anyone tell me what is wrong with my program in order for it to work in c++?

/*
Program Calculator Week3 Individual Assignment
Version 2.2
Date: March 17, 2006
Display the amount of monthly payment amount for a mortgage payment enter by user to display loan amount, interest rate, and term of loan.
*/
#include <math.h>
#include <string>
#include <iostream>

using namespace std

int main()
{
// Set variables use for mortgage payment
double amount;                // Loan amount
int term;                     // Loan term
int month = 12;               // 1 year = 12 months
int term_months;              // Loan term in month
double rate;                  // Loan interest rate
int choice;                   // Used for choice dialog
double monthly_payment;       // Variable for monthly payment
double term_rate;             // Holds percentage as a decimal

cout << "Enter the loan amount in dollars: ";
cin >> amount;

cout << "Enter the loan term in years: ";
cin >> term;

cout << "Enter the interest rate as a percentage: ";
cin >> rate;

term_months = (term*12);    //Converts years to months
term_rate = (rate/100);         // Converts Percentage to Decimal

double amortization_factor = 1 + (rate / 100 / 12);
monthly_payment = amount * (amortization_factor - 1.0) / (1.0 - pow(amortization_factor, -term_months));

cout <<  "Your Mortgage amount is\n";
cin <<  "Amount: \$ " <<  amount << endl;                   //Prints out Amount
cout <<  "Your Mortgage is being taken out for" << endl;
cin <<  "Years: " << term << endl;                         //Prints out Term
cout <<  "The interest rate is\n";
cin <<  "Percent: " << rate << endl;                       //Prints out Rate
cout <<  "Your Monthly Payment Amount is " << endl;
cin <<  "Payment Amount: \$ " << monthly_payment <<endl;    //Prints out monthly payment

//Allows the user to end or start over

char ans;
do
{
cout<< "Do you want to continue (Y/N)?\n";
cout<< "You must type a 'Y' or an 'N'.\n";
cin >> ans;
}
while((ans !='Y')&&(ans !='N')&&(ans !='y')&&(ans !='n'));

/*the loop continues until the user enters the correct response*/
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I don't know about the math part, but I see two problems:
1) You missed a ";" after "using namespace std"
2) The last four lines starting with "cin" should be changed to "cout"
0
Author Commented:
I have corrected the information you provided but I am still having major issues with this program.  Help anyone
0
Commented:
0
Commented:
I agree. I made the changes kjpus suggested, and it compiles with a single warning (the variable choice isn't used).

What happens when you compile? What are you compiling with?

--
Troy
0
Author Commented:
The only problem that I am getting now is that my math calculation does not appear to be working correctly after making all the changes that has been mention.  Here is my code as of today.

#include <math.h>
#include <string>
#include <iostream>
using namespace std;

int main()
{
// Local variable declarations of main
double amount;                // Loan amount
int term;                        // Loan term
int month = 12;               // 1 year = 12 months
int term_months;              // Loan term in month
double rate;                  // Loan interest rate
char choice;                   // Used for choice dialog
double monthly_payment;       // Variable for monthly payment
double term_rate;             // Holds percentage as a decimal

// Introduction:
// Display the title and the purpose of the program to the user
do {
cout << "Enter the loan amount in dollars: ";
cin >> amount;

cout << "Enter the loan term in years: ";
cin >> term;

cout << "Enter the interest rate as a percentage: ";
cin >> rate;

// Input Module
// This module asks the user to enter in the amounts for the principal,
// annual interest rate and the number of years.

term_months = (term*12);    //Converts years to months
term_rate = (rate/100);         // Converts Percentage to Decimal
//mortgage calculation
monthly_payment = ((amount*term_rate/month*pow(term_rate/month+1,term_months))/(pow

(term_rate/month+1,term_months)-1), 2) ;

cout <<  "Your Mortgage amount is\n";
cout <<  "Amount: \$ " <<  amount << endl;                   //Prints out Amount
cout <<  "Your Mortgage is being taken out for" << endl;
cout <<  "Years: " << term << endl;                         //Prints out Term
cout <<  "The interest rate is\n";
cout <<  "Percent: " << rate << endl;                       //Prints out Rate
cout <<  "Your Monthly Payment Amount is " << endl;
cout <<  "Payment Amount: \$ " << monthly_payment;           //Prints out monthly paymet

//Allows the user to re-enter information or exit out program
cout << "Would you like to perform another calculation? ";
cin >> choice;
} while (choice == 'Y' || choice == 'y');
return 0;

}
0
Commented:
What is it supposed to be calculating?  Can you give an example of the some sets of values you're entering, what you expect as output, and what the output currently is?
0
Commented:
Your math doens't work because - well, your equation is not right. It should be:

monthly_payment=amount*term_rate/month/(1-pow(1+term_rate/month,-term_months));

Now you can finish your homework:)
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
I like to start off by thanking both of you for assisting me in something that had me going for quite awhile.  I am going to look over and see why my equation ends up being wrong in the first place.

Thanks
0
Commented:
If you look at the modified monthly_payment formula, you'll notice yours is mathematically the same as mine if you remove the ",2" part. What happened to your statement is that the stuff before comma is evaluated to the correct monthly_payment but the ",2" is a seperate statement. And in C, if you seperates two statements with comma, it will evaluate to the latter half. That's why you always get a monthly_payment of 2.
0
Author Commented:
My program is listed above.

Help anyone looking to add some more information to my program that allows me to moddify the mortgage program to input the amount of the mortgage, the term of the mortgage, and the interest rate of the mortgage.

Display the mortgage payment amount.  Then, list the loan balance and interest paid for each payment over the term of the loan.  On longer-term loans, the list will scroll off the screen.  That does not let the information scroll off the screen, but display a partial list and then allow the user to continue the list.  Allow the user to loop back and enter new data or quit.

I know that I should be able to show a 6 month plan and than allow the user to input to get the rest of it so it would not scroll of the screen.  I have been having a hard time understanding how to do it.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.