In article <G7mdnUmW-q39ynXYnZ2dnUVZ_tadnZ2d@giganews.com>, Nathan
(dydx13@hotmail.com) says...
[ ... ]
Quote:
cout<<"Please enter hours worked ( -1 to exit):";
cin>>hworked;
You may not have reached the point in the book where they've taught you
how to do so, but if you know about functions, I'd write a small one to
do this part, something like:
double get_double(std::string const &prompt) {
std::cout << "Please enter " << prompt;
double ret;
std::cin >ret;
return ret;
}
The rest could benefit from using descriptive names for more of what
you're doing:
double full_time = 40.0;
double overtime_multiplier = 1.5;
double overtime_hours = 0.0;
if (hworked full_time) {
hworked = full_time;
overtime_hours = hworked - standard_hours;
}
double standard_pay = rate * standard_hours;
double overtime_pay = rate * overtime_multiplier * overtime_hours;
double salary = standard_pay + overtime_pay;
As far as the structure of the program goes, I don't like the fact that
you ask the user to the hours worked in two different places. Above,
I've used a function to isolate most of that into one place, but that's
still not really sufficient (IMO). I'd prefer a structure more like:
while (-1.0!=(hworked=get_double("hours worked (-1 to exit): ") {
double rate = get_double("hourly rate: ");
std::cout << "Salary is: " << compute_salary(hours, rate);
}
where compute_salary contained code similar to the previous computation.
--
Later,
Jerry.
The universe is a figment of its own imagination.