Write a program using an array. The array contains the hours worked for 5 employ
ID: 3554686 • Letter: W
Question
Write a program using an array.
The array contains the hours worked for 5 employees. These hours are entered by the user.All employees earn the same hourly wage. The program will calculate the gross pay for each employee. Hint: the gross pay for each employee (an element in an array) : array[index] * hourly wage
ask the user to enter the hours worked - refer to employee as employee 1,2,etc (see sample output)
- ask the use for the hourly wage
- display the gross pay for each employee
- display gross pay with 2 decimal places (not shown in sample output)
Explanation / Answer
#include<stdio.h>
int main(){
float employee[5],grossPay,hourPay;
int i;
for(i=0; i<5; i++){
printf("Enter the hours worked by employee %d : ",i+1);
scanf("%f",&employee[i]);
}
printf("Enter the hourly wage : ");
scanf("%f",&hourPay);
for(i=0; i<5; i++){
printf("The gross pay for employee %d is ",i+1);
printf("%.2f ",employee[i]*hourPay);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.