1. 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?

Code:
```#include <iostream>
using namespace std;

float compute_net(float tax, int hours = 40, int rate = 5); //prototype

main()
{
int hours;
int rate;
float tax;
float ans;
cout << "How many hours did you work? \n";
cin >> hours;

cout << "How much do you make per hour? \n";
cin >> rate;

cout << "How much tax do you pay? \n";
cin >> tax;

ans = compute_net(tax, hours, rate);
cout << ans;

return 0;
}

float compute_net(float tax, int hours, int rate)
{
float net;
net= (hours*rate) - (hours*tax);
return(net);
}```

2. If programming were easy, it wouldn't be worth doing. Here's a really good hint:
Code:
```#include <cstdlib>
#include <iostream>
#include <string>

int main()
{
std::string line;
int x = 40;

std::cout<<"Enter x: ";
std::getline ( std::cin, line );

if ( line != "" )
x = std::atoi ( line.c_str() );

std::cout<< x <<'\n';
}```
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).

3. 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.

4. You know what... I didn't even learn std and all the functions that come with it... Is there a way to do it more simple? The focus is on Default Arguments.

5. 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.

Hopefully you have learned about if statements at this point.