30.8k views
1 vote
Assume the input data is structured as follows: first there is a non-negative integer specifying the number of employee timesheets to be read in. This is followed by data for each of the employees. The first number for each employee is an integer that specifies their pay per hour in cents. Following this are 5 integers, the number of hours they worked on each of the days of the workweek.Given this data and given that an int variable total has been declared, write a loop and any necessary code that reads the data and stores the total payroll of all employees in total. Note that you will have to add up the numbers worked by each employee and multiply that by that particular employee's pay rate to get the employee's pay for the week-- and sum those values into total.

User Yurzui
by
5.3k points

2 Answers

1 vote

Answer:

The structure of the following program

int numberOfTimesheets;

int centsPerHour = 0;

int hoursWorked;

total = 0;

numberOfTimesheets = stdin.nextInt();

for(int i = 1; i <= numberOfTimesheets; i++)

{

hoursWorked = 0;

centsPerHour = stdin.nextInt();

for (int ii = 1; ii <= 5; ii++)

{

hoursWorked = hoursWorked + stdin.nextInt();

}

total = total + (hoursWorked * centsPerHour);

}

Step-by-step explanation:

User Degant
by
5.8k points
5 votes

Answer:

The structure of the following program:

int employees;

int a,b;

int wage=0;

int hours=0;

total=0;

cin >> employees;

for (a=1; a<=employees; a++){

cin >> wage;

for (b=1; b<=5; b++){

cin >> hours;

total += hours * wage;

}

}

Explanation:

Firstly, we set non-negative integer type variables "a" and "b", than set two more integer type variables "wage" and "hours", after that gets input in the variable "employees", than set for loop which is starts from 1 and ends according to the length of the employees and gets input in the variable wages and then repeat this process with hour, after all we sum those value in total.

User Eliad
by
5.0k points