Editing input values

I am working on my C++ mid-term and am having a total brain meltdown.

I am being asked to create a linear straight-line (no functions) program to calculate monthly car payments.

Part of the instructions state:
"You are to use a while loop to get the value (of "float price") from the keyboard. You will edit the input value to ensure that the price value is greater than $50.00 and less than $50,000.00."

What the heck does he mean by edit the input value to make it between $50 and $50000?

Any help would be greatly appreciated!



Here is the full instructions for the program:

You are to write a C++ program to calculate the monthly car payment(s) for a customers.. You have read ahead in your textbook and know that it would be really neat to use functions for this task. Unfortunately you have not had functions yet and you must resort to a linear straight-line program. (In other words, you are not to use functions.) As much as possible you are to develop the code as modular building blocks. 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.


Your overall program structure will consist of:
• Declarations and initializations
• Input price of vehicle
• Input trade in value
• Input down payment
• Input annual interest rate
• Calculate monthly loan payments
• Display (output) results

All input routines are to have informative and clear instructions for entering values. The input routines are to keep the user in the routine until an entry is valid. Your program should be well organized, use the suggested variable names, proper indentations, and appropriate comments. You are to use the concepts we have covered in the first seven chapters and are not to use capabilities found in chapters eight through twelve (such as functions, enums, arrays, structs, or classes). The input of all variables is via the keyboard (cin). The display routine is to use cout via the standard monitor.



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.

CODE SECTIONS
Main Declarations and main
Get price Input price of vehicle
Get interest rate Input the annual interest rate as a decimal fraction.
Get down payment Input down payment in dollars and cents.
Get tradein Input trade in in dollars and cents
Calculate monthly payment Calculate the monthly payment using the supplied equations
Display loan schedule Display the pertinent loan data and calculation results.
Exit routine Terminate program

Your programming manager has directed you to produce blocks of modular routines to perform different tasks.

Get price routine 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.

Get tradeIn routine 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.
.
Get downPayment routine 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. .

Get annualIntRate routine 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.

Calculate monPayment routine You are to use the monPayment equation to calculate 4 monthly payment amounts. You are to calculate a monthly payment for 24, 36, 48, and 60 months.

Display loan schedule You are to display the pertinent loan information. The report format and contents are shown below.

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. The attached midterm grading guideline provides an example that you can use to verify your work.
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
What the heck does he mean by edit the input value to make it between $50 and $50000?


Sounds like he wants you to clip the input so that the value is always within that range.

So if the user enters 45, you would change it to 50. Or if they input 60000, you would change it to 50000.


Also not being able to use functions blows.
You could use macros for your functions, and then compile with -E (GCC) or with /P (VC++). Noone would notice it anyways.

(but seriously, that's the dumbest requirement ever. It's akin to saying write a program that does stuff, and you're only allowed to use underscores and digits for variable names...).
Last edited on
Disch,
That ,also, is the way I was interpreting it. I am just not really sure how to go about doing that with a while loop. Normally I would use:

1
2
3
4
if (price < 50.0)
price = 50.0
if (price>50000.0)
price = 50000.0


...if only I could turn that into a while loop...I feel like my brain is stuck in a infinite loop!

Thanks for your reply!
Ah.. yeah good question. I'm not sure what he means by that either.

Maybe you're not supposed to clip the input, but instead are supposed to loop until the user inputs a value between 50 and 50000?
Great idea! That is what I am going to do. Then it won't be a continuous loop if someone does input the proper values. As I reread the instructions I see that my professor wrote "The input routines are to keep the user in the routine until an entry is valid". Your suggestion must be what he means! I have been beating my head against the wall all day over this. Thanks!
Topic archived. No new replies allowed.