I have spent a bit of time without much sucess on this program. I would appreciate any help you can offer.
The odd thing is the output from the build does not match the lines and that makes it even more confusing. The formulas;
interest_payment = current_principal * monthly_interest_rate;
current_principal = current_principal - (monthly_payment - interest_payment);
are from the instructor...in case you wonder where they came from. He also wants us to insert the code that is associated with the pseudocode...
if ((month % 12 == 0) & (month+1 < term * 12))
prompt the user whether to show more data...
if user says no
break from the loop
endif
endif
Which has me at a loss.
Susan
//-----------------------------------------
//Course: PRG/410 - C++ Programming
//Author: Susan R. Stephenson
//Date: February 18, 2008
//Title: Mortgage Calclator Week 4 Individual Assignement
//------------------------------------------
//C++ program enhancement #2 (15 points). Modify 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 loans, the list will scroll off the screen. Display a partial list and
//give the user the option to continue or exit. Allow the user to loop back and
//enter new data or quit. Insert meaningful comments at least once for every few
//lines of the program. Run your program for the following input data & capture
//the output: ($50000, 2 years, 7%) followed by ($1000000, 10 years, 8%) followed
//by ($10000, 1 year, 6%). Submit the source code and the program output to
//Individual forum.
#include <cmath>
#include <iostream>
using namespace std;
float A = 0; //Total loan amount
float i = 0.00; //Loan interest rate
int y = 0; // Length of loan in years
int quit = 1; // loop function if user wants to quit
float pay = 0; // Calculation of payment amount
int main()
{
do
{
cout << "Enter total loan amount without commas and press Enter:\n"; //Prompt the user & get the mortgage amount as input
cin >> A;
cout << "Enter loan years and press Enter:\n";// Prompt the user and get the # of years as input
cin >> y;
cout << "Enter interest rate in 0.0000 format and press Enter:\n"; //Prompt the user a & get the interest rate as input
cin >> i;
pay =(A*((i/12)/(1- pow((1+(i/12)),-(y*12))))); //Apply the formula to compute the monthly mortage payment
cout << "The payment is: $"<< pay<<"\n";//Output the monthly mortgage payment amount
double principal; //amortization table
double totalInterestPaid;
double balance;
double interest_payment;
double current_principal;
double monthly_interest_rate;
double monthly_payment;
double numberOfPayments;
totalInterestPaid = 0; //assign values
//title for table
cout<<"Balance******Interest Paid******Remaining Payments"<< endl;
cout<< endl;
do
{ //Calculations to perform
interest_payment = current_principal * monthly_interest_rate;
current_principal = current_principal - (monthly_payment - interest_payment);
balance = balance - principal;
numberOfPayments = numberOfPayments - 1;
for (int numberOfPayments = 0; numberOfPayments >0; numberOfPayments++)
//set up table
cout.width(7);
cout<<balance<<"";
cout.width (20);
cout<<totalInterestPaid<<"";
cout.width(22);
cout<<endl;
}
while (numberOfPayments>0);
if (numberOfPayments*12==0);
cout << "Select 1 to enter different values or 2 to quit\n";//Prompt user whether (s)he has another set of data & get the input
cout<<"Thank you!\n"; //Thank the user and quit
cin >> quit;
} while (quit==1);
return 0;
}
output
----- Build started: Project: Week04, Configuration: Debug Win32 ------
Compiling...
004b.cpp
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\004b.cpp(87) : warning C4390: ';' : empty controlled statement found; is this the intent?
04c.cpp
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(53) : error C2065: 'totalTerm' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(55) : warning C4091: '' : ignored on left of 'char' when no variable is declared
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(55) : error C2143: syntax error : missing ';' before 'constant'
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(56) : warning C4091: '' : ignored on left of 'char' when no variable is declared
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(56) : error C2143: syntax error : missing ';' before 'constant'
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(59) : error C2065: 'mortgageAmount' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(67) : error C2065: 'interest_payment' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(67) : error C2065: 'current_principal' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(67) : error C2065: 'monthly_interest_rate' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(68) : error C2065: 'current_principal' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(68) : error C2065: 'current_principal' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(68) : error C2065: 'monthly_payment' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(68) : error C2065: 'interest_payment' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(70) : error C2065: 'monthlyInterest' : undeclared identifier
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(73) : error C3861: 'setprecision': identifier not found
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(81) : error C2039: 'witdth' : is not a member of 'std::basic_ostream<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(87) : warning C4390: ';' : empty controlled statement found; is this the intent?
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(98) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\04c.cpp(31)' was matched
Week04.cpp
4D.cpp
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\4d.cpp(87) : warning C4390: ';' : empty controlled statement found; is this the intent?
Generating Code...
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\4d.cpp(68) : warning C4700: uninitialized local variable 'current_principal' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\4d.cpp(68) : warning C4700: uninitialized local variable 'monthly_interest_rate' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\4d.cpp(69) : warning C4700: uninitialized local variable 'monthly_payment' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\4d.cpp(70) : warning C4700: uninitialized local variable 'balance' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\4d.cpp(70) : warning C4700: uninitialized local variable 'principal' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\4d.cpp(71) : warning C4700: uninitialized local variable 'numberOfPayments' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\004b.cpp(68) : warning C4700: uninitialized local variable 'current_principal' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\004b.cpp(68) : warning C4700: uninitialized local variable 'monthly_interest_rate' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\004b.cpp(69) : warning C4700: uninitialized local variable 'monthly_payment' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\004b.cpp(70) : warning C4700: uninitialized local variable 'balance' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\004b.cpp(70) : warning C4700: uninitialized local variable 'principal' used
c:\documents and settings\susan\my documents\visual studio 2008\projects\week04\week04\004b.cpp(71) : warning C4700: uninitialized local variable 'numberOfPayments' used
Build log was saved at "file://c:\Documents and Settings\Susan\My Documents\Visual Studio 2008\Projects\Week04\Week04\Debug\BuildLog.htm"
Week04 - 15 error(s), 17 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Please use code tags:

New Topic/Question
Reply



MultiQuote




|