Default Arguments Question...

This is a discussion on Default Arguments Question... within the C++ Programming forums, part of the General Programming Boards category; This is a question I'm stuck with from the book "C++ Programming 101" :
Write a program that computes net ...

Default Arguments Question...

This is a question I'm stuck with from the book "C++ Programming 101" :

Write a program that computes net pay based on the values the user types, Ask the user for the hours worked, the rate per hour, and the tax rate. Because most employees work 40 hours per week and earn $5.00 per hour, use these values as default values in the function that computes the net pay. If the user presses Enter in response to your questions, use the default values.

Here is what I got so far: I don't know what to do with the Enter.. How do I do that if the user presses Enter the default values will be sent?

I urge you to keep something on the backburner though: atoi is easy, but sucks ass when the string doesn't represent a valid integer. A better solution is strtol, and even better for C++ is stringstream (see the FAQ).

That is a difficult thing to do for a beginner, I'm surprised the book asked you to do it. When the user hits enter, the operator>> treats it like whitespace and keeps waiting for more input.

One way to solve it would be to use the noskipws manipulator. Another would be to use getline to read into a string and check for an empty string before converting it to the number you need. Both are slightly more advanced options than the code in your program.

Also, you should read in the rate as a floating point number as well, since somebody making 5.50 an hour would not be able to use the program you have now.

I would skip the part about checking to see if the user hit enter until you learn more about user input and cin.

To test your default arguments, try asking the user for a number - 1, 2, or 3. If they give you 1, then ask only for the tax and call the function by only passing in the tax. If they hit 2, ask for the tax and hours and call the function by only passing in the tax and hours. If they hit 3, ask for the tax, hours, and rate and call the function by passing in all three values.