Write a program to calculate gross income and net income for all employees in a company. At the end, also print out the total gross, total net, average gross, and average net. Overtime (over 40 hours) should be paid at a time and a half of rate. Income tax is a fixed percentage of 20%.
First, ask the user how many employees he has and then use a count controlled loop to loop through each of his employees to calculate their income. # of employees must not be negative.
My coding so far:
#include <iostream>
using namespace std;
int main()
{
const double regular_hours = 40;
int employee_name, employee_count, another_employee, hours_worked;
double total_gross, total_net, average_gross, average_net, rate;
cout << "How many employees in this week's payroll?: " << endl; // cout = console output
cin >> employee_count; // cin = console input
(1) Please use code tags for code samples. (See the first item in the format menu to the right, or put them in manually as [code] and [/code].)
(2) Unless you are in North Korea, employees have names, not numbers, so it would be better to have employee_name as a std::string rather than an int.
(3) You need a for loop around the input and processing for each employee. (In the future, if you want to store them all for later then you can consider arrays (and, ideally, structs).)
(4) For negative employee_count you ask the user to input the value again ... but don't give him/her any way of doing so. Personally, I would leave input checks like this to last and concentrate on the main sequence of calculations first.