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

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*/

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

MilianoAuthor Commented:

I have corrected the information you provided but I am still having major issues with this program. Help anyone

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

MilianoAuthor 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;

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?

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.

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

MilianoAuthor 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

Featured Post

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

1) You missed a ";" after "using namespace std"

2) The last four lines starting with "cin" should be changed to "cout"