To anyone who can help...I'm trying to implement class/structure into my code, I overlooked this as part of my assignment and don't know how to implement without changing the code too much(it took me forever to get this right)...also, the underlined bold section (lines 116-121) is a recommendation I received from a friend but when I tried to implement it it gives me errors (no declaration or storage class)...if you can help me, please do. -
-
#include <iostream>
-
#include <iomanip>
-
#include <math.h>
-
#include <limits>
-
using namespace std;
-
-
// End Headers
-
-
double getLoanAmount();
-
int getLoanChoice();
-
-
void calculateMonthlyPayments(double loanAmount , double interestRate , double payment, int termInMonths);
-
void printOutput(int month , double H , double C , double loanAmount);
-
-
-
-
int main()
-
{
-
double loanAmount ;
-
double interestRate[] = { .0535 , .055 , .0575 } ;
-
int termInMonths[] = { 7*12 , 15*12 , 30*12 } ; // in months
-
-
int quit = 0;
-
do
-
{
-
loanAmount = getLoanAmount();
-
-
int num = getLoanChoice();
-
-
// monthly payment calculation formula
-
double payment = loanAmount * (( interestRate[num-1]/12) /(1-pow( 1 / ( ( 1 + interestRate[num-1] / 12 ) ) , termInMonths[num-1] ) ) );
-
-
// display the payment amount
-
cout << fixed << setprecision(2) <<"Monthly Payment:\t$" << payment << endl;
-
-
// calculate and print monthly payments
-
calculateMonthlyPayments( loanAmount , interestRate[num-1] , payment, termInMonths[num-1] );
-
-
cout << "\n1. Enter new data" << endl;
-
cout << "2. Quit" << endl;
-
cout << "Select a choice: ";
-
cin >> quit;
-
}
-
while ( quit != 2 );
-
-
return 0;
-
}
-
-
// input loan amount
-
double getLoanAmount()
-
{
-
double loanAmount;
-
// input loan amount
-
cout << "Enter Loan amount:" ;
-
cin >> loanAmount;
-
return loanAmount;
-
}
-
// input choice of user
-
int getLoanChoice()
-
{
-
int num;
-
do
-
{
-
cout << "1. 7 year at 5.35%\n2. 15 year at 5.5%\n3. 30 year at 5.75%\nSelect a mortgage loan: ";
-
cin >> num;
-
} while ( num < 1 || num > 3 );
-
return num;
-
}
-
// Calculate monthly payments of each installment
-
void calculateMonthlyPayments(double loanAmount , double interestRate , double payment, int termInMonths)
-
{
-
-
// Heading of output
-
cout << "\nMonth\t\tMonthly\t\tPrinciple\t\tBalance" << endl;
-
cout << "\n\t\tInterest\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" << endl;
-
cout << "\n______________________________________________________________________" << endl;
-
double J = interestRate / 12 ;
-
double H = 0 , C = 0, Q = 1 ;
-
int month = 1;
-
-
// do
-
// {
-
double HSum = 0 , CSum = 0 ;
-
for ( int i = 1 ; i <= termInMonths ; i++ )
-
{
-
// calculate current monthly interest
-
H = loanAmount * J ;
-
// loanAmount amount to be paid in that month
-
C = payment - H ;
-
CSum = CSum + C ;
-
HSum = HSum + H ;
-
// new balance of loanAmount of loan
-
loanAmount = loanAmount - C ;
-
-
if ( loanAmount > 0 )
-
{
-
// display output
-
printOutput(month++ , H , C , loanAmount);
-
-
}
-
// if 12 lines has been displayed then pause
-
if ( month % 12 - 1 == 0 )
-
{
-
// pause
-
cout << "Press Enter to continue viewing table." << endl;
-
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
-
//cin.get();
-
}
-
}
-
Q = loanAmount;
-
-
// set loanAmount to Q for next loop iteration
-
loanAmount = Q;
-
- }
-
while ( loanAmount >= 0 );
-
loanAmount = 0;
-
printOutput(month++ , H , C , loanAmount);
-
-
}
-
-
// display the monthly payment
-
void printOutput(int month , double H , double C , double loanAmount)
-
{
-
cout << month << "\t\t$" << fixed<< setprecision(2) << H << "\t\t$" << C << "\t\t$" << loanAmount << endl;
-
}
-
-
void printInformation(double loanAmount , double interestRate , double termInMonths, double payment)
-
-
-
{
-
-
}
-
-
-
1 1551
It looks like a screwed-up whiuole loop.
This code: - loanAmount = Q;
-
-
}
-
while ( loanAmount >= 0 );
-
loanAmount = 0;
-
printOutput(month++ , H , C , loanAmount);
-
-
}
a) has a ; in the while statement so there is really no loop. loanAmount is not defined inside the current scope.
It goes out of scope due to the }.
It looks like you want: - loanAmount = Q;
-
-
while ( loanAmount >= 0 )
-
{
-
loanAmount = 0;
-
printOutput(month++ , H , C , loanAmount);
-
-
}
instead.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: grahamo |
last post by:
This came up in an interview I did a while ago and I wanted to know
the correct answer. The setup is this;
If I have a base class "food" and also two classes "meat" and "veg"
that inherit from...
|
by: Erik H. |
last post by:
I have an ASPX page in which I am trying to bind a datagrid to a dataset
pulled from Microsoft Access DB using code inline method. For some reason,
the compiler is having a problem with 'using'....
|
by: SB |
last post by:
I feel dumb to ask because I bet this is a simple question...
Looking at the code below, can someone please explain why I get two
different values in my Marshal.SizeOf calls (see the commented...
|
by: Erik H. |
last post by:
I have an ASPX page in which I am trying to bind a datagrid to a dataset
pulled from Microsoft Access DB using code inline method. For some reason,
the compiler is having a problem with 'using'....
|
by: Lyle Avery |
last post by:
Hello guys,
Look at this in c++ file:
class T
{
public:
char c;
char ca;
};
|
by: stromhau |
last post by:
Hi,
I have made a few classes in c++. They somehow cooperate doing some 3d stuff.
Basically it is a moving camera acting as a flight, i have placed a lot of objects around the scene together with...
|
by: cr55 |
last post by:
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed now is error: C2228: left of '.rent' must have...
|
by: yalbizu |
last post by:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int NO_OF_STUDENTS=20;
struct studentType
{
string studentFName;
string studentLName;
|
by: rajatamilarasu |
last post by:
for(i=0 ; i<listNum ; i++) {
checker.checkN1DisagreementSwitch(pRep_Active_SList.ChassisID, pRep_Active_SList.SlotID,
pRep_Standby_SList.ChassisID, pRep_Standby_SList.SlotID);
...
|
by: =?Utf-8?B?Y2hyaXNiZW4=?= |
last post by:
Hi,
Assuming I have a class/struct with only following types
float, int, string
what is the most efficient way to pack it to a single byte array before I
send it out. I tried to use...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |