/**************************************************************** * Weekly Pay: A program to calculate an employee's * * weekly pay including time-and-a-half for any * * hours over forty. * * * * Author: Daniel Emmons * * * * Purpose: to complete Exercise 6-5 as found in the * * book "Practical C++ Programming" by Steve Oualline * ****************************************************************/ #include float hours; // the hours worked as given by the user float minus40; // the hours worked minus 40 float wage; // the hourly wage of the employee float regular; // the employee's regular wages float overtime; // the employee's overtime wages int main() { std::cout << "Enter the number of hours the employee worked: "; std::cin >> hours; while(hours != 0){ std::cout << "\nEnter the employee's hourly wage in dollars: "; std::cin >> wage; if(hours < 0){ std::cout << "\nPlease enter a positive number for the hours: "; std::cin >> hours; } if(wage < 0){ std::cout << "\nPlease enter a positive number for the wage: "; std::cin >> wage; } if(hours == 40){ regular = 40 * wage; std::cout << "\nThe employee earned $" << regular << " in regular wages.\n"; std::cout << "The employee did not earn any overtime wages.\n"; } if(hours > 40){ regular = 40 * wage; overtime = (hours - 40) * wage * 1.5; std::cout << "\nThe employee earned $" << regular << " in regular wages.\n"; std::cout << "The employee earned $" << overtime << " in overtime wages.\n"; std::cout << "The employee earned a total of $" << regular + overtime << ".\n"; } if(hours < 40){ regular = hours * wage; std::cout << "\nThe employee earned $" << regular << " in regular wages.\n"; std::cout << "The employee did not earn any overtime wages.\n"; } std::cout << "\nEnter the number of hours for another employee,\n"; std::cout << "or enter 0 (zero) to exit: "; std::cin >> hours; } return (0); }