I have to do an assignment for class along these lines:
Use a for loop to process the data for 5 employees. Use arrays to store the user input. In the for loop, if any of the entered fields are –1, break out of the loop.
The program logic will first load all of the data, until the user enters the max number of records, or they input -1 for one of the fields. After the data is loaded, it will then be processed and output generated.
I'm confuse on how to do the array which has to look similar to this:
Enter name: Glenn
Enter hourly rate: 2.00
Enter hours worked: 50
Pay to: Glenn
Hours worked: $ 50.00
Hourly rate: $ 2.00
Gross pay: $110.00
Base pay: $ 80.00
Overtime pay: $ 30.00
Taxes paid: $ 22.00
Net pay: $ 88.00
The teacher wants us to update our previous assignment. I'm not sure how to integrate. Here is my code:
Code:#include <stdio.h>
#include <stdlib.h>
#include <conio.h> /* using this for getch */
int main(void)
{
//Start of integers
/* Ppl names */
char name[20];
/* Hourly rate */
float hrr;
/* Hours worked */
float hrw;
/* Amount paid */
float ap;
/* Taxes paid */
float tp;
/* Loop int */
int looper;
//End of integers
for (looper = 0; looper < 5; looper++){
/*START OF RUN*/
//Start of user input
printf("Employee name:");
scanf("%s", &name);
fflush(stdin);
printf("Enter hourly rate:");
scanf("%f", &hrr);
printf("Enter hours worked:");
scanf("%f", &hrw);
printf("\n");
//End of user input
//Start of equations
if (hrw>40){
ap=40*hrr+(hrw-40)*(1.5*hrr);
}
else{
ap=hrw*hrr;
}
tp=ap*0.2;
//End of equations
//Start of calculated data
printf("Pay to: %s \n", name);
printf("Hourly rate: %f \n", hrr);
printf("Hours worked: %f \n", hrw);
printf("Amount paid: %f \n", ap);
printf("Taxes paid: %f \n", tp);
//End of calculated data
/*END OF RUN*/
printf("----------------------------------\n");
}
getch();
return 0;
}