I just started using C++ and have a practice exercise, can anybody do this? It seems complicated.

You have been requested by “Honest Dave’s Used Cars” to write a program to calculate the monthly car payment for their customers.. As much as possible you are to develop the code as independent modules. You should have a small “driver” main module with a series of calls that invokes the various routines. You are encouraged to use functional decomposition to design your program. You are to USE NO GLOBAL VARIABLES in your work. You should manually calculate some values to ensure that your program is working correctly.

You are to prompt for the following:

Price of the vehicle.
Trade-in value.
Down-payment.
Annual interest rate.


Variable Description Data Type
price
Price of vehicle
float

downPayment
Down Payment
float

tradeIn
Trade in for vehicle
float

loanAmt
Loan Amount (calculated)
float

annualIntRate
Annual Interest Rate (fraction)
float

annualIntPercent
Annual Interest Rate (percent)
float

monIntRate
Monthly Interest Rate (fraction)
float

noMonths
Number of Monthly Payments (24, 36, 48 & 60)
int

monPayment
Monthly Payment
float


monIntRate = annualIntRate / 12.0
annualIntPercent = annualIntRate * 100.0

loanAmt = price – downPayment – tradeIn

monPayment = (loanAmt * monIntRate)/(1.0 –(1+monIntRate) –noMonths ) where noMonths = 24, 36, 48, & 60. Also note that the exponent in the above equation is negative.

FUNCTIONS


getPrice
Get price of vehicle

getInterestRate
Get the annual interest rate from the keyboard as a fraction.

getDownPayment
Get down payment from keyboard in dollars and cents.

getTradeIn
Get trade in from keyboard in dollars and cents

calcMonPayment
Calculate the monthly payment using the supplied equation


Your programming manager has directed you to produce “small” independent routines to perform different functions in the software.

1. Get price function.

getPrice
You are to use a while loop to get the value from the keyboard. You are to edit the input value to ensure that the price value is greater than $50.00 and less than $50,000.00.


2. Get trade in function.

getTradeIn
You are to use a while loop to get the value from the keyboard. You are to edit the input value to ensure that the tradeIn value is greater than or equal to zero and less than the price.


3. Get down payment function.

getDownPayment
You are to use a while loop to get the value from the keyboard. You are to edit the input value to ensure that the downPayment value is greater than or equal to zero and less than the price minus the trade in.


4. Get interest rate function

getInterestRate
You are to use a while loop to get the value from the keyboard. The interest rate is to be entered as a decimal fraction. For example .06 would be entered rather than 6%. The annual interest rate must be greater than or equal to zero and be less than .50. The annual interest rate is to be passed by value to/from the calling program.


5. Calculate monthly loan payment

calcMonPayment
You are to use the monPayment equation as the basis of a function to calculate the monthly payment amount. You are to calculate a monthly payment based upon 24, 36, 48, and 60 months.


You are to align your columns (this example may not be aligned correctly) and display two places to the right of the decimal. You are given the following report example.

Honest Dave’s Used Cars

Vehicle price 99999.99

Trade in value 99999.99

Down payment 99999.99

----------

Loan amount 99999.99

Annual interest rate 99.99%

Monthly payment options

24 months 9999.99

36 9999.99

48 9999.99

60 9999.99

I'm trying to do section off functions by themselves first. Just so you know, I'm not looking for someone to do my homework.
I have this so far, but I still have no idea what I'm doing:

#include "stdafx.h"
#include "iostream"
#include "iomanip"

int main()
{
}
int GetPrice();
{
    cout<<"What is the price of the vehicle?"<<endl;
    getPrice;
}

Missing Function Header, the first brace under GetPrice()

>>I'm trying to do section off functions by themselves first
Excellent appropach to the problem. Do it just a little bit at a time and you won't have so many problems.

Line 8: remove the semicolon at the end of the line. That is a very very common error that we all get occasionally.

lines 2 and 3: those header files belong in angle brackets, not quotes

#include <iostream>
#include <iomanip>

The only header files you put in quotes are the ones you create yourself and are in your project directory or those that may be located in some non-standard directory that your compiler doesn't know about.

>>I'm trying to do section off functions by themselves first
Excellent appropach to the problem. Do it just a little bit at a time and you won't have so many problems.

Line 8: remove the semicolon at the end of the line. That is a very very common error that we all get occasionally.

lines 2 and 3: those header files belong in angle brackets, not quotes

#include <iostream>
#include <iomanip>

The only header files you put in quotes are the ones you create yourself and are in your project directory or those that may be located in some non-standard directory that your compiler doesn't know about.

I meant to put brackets, I had them on paper. If I remove the semicolon then I get an error saying cout is an unknown identifier, endl is unknown identifier or not defined or something like that

That means you still have errors. You three options to resolve that problem -- they are all correct but some are better than others.

1) put using namespace std; at the end of the include list, on line 4. This is probably the least preferred option.

2) add using statements for each function you want to use from the std namespace on line 4

using std::cout;
using std::endl;
// do the same with all the rest of the functions

3) Identify the namespace inside the code itself. I don't like this though because it makes the code look somewhat awkward. std::cout<<"What is the price of the vehicle?"<< std::endl;

Thanks, I've completed it all today.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.