#include #include #include /*This is the main method for a simple C program to accept a list containing an * employee's name, the hours they have worked, and their rate of pay. The * program then outputs all the information entered to the screen in an easily * readable format. * Input: hours, rate, and name for each employee * Output: Input information, as well as total pay in a formatted table * Return: Type is int, value is 0 */ int main() { /*declares all variables*/ float rate; float hours; char name[80]; char *ptr; int count; /*Prompt to specify information needed, and order to input it*/ printf("\nEnter hours, rate, and name. Ctrl D to exit\n\n"); /*sets default value for count which controls when table labels * print to screen*/ count=0; /*while loop to collect data input by user, and then print formatted * back to screen*/ while(scanf("%f %f",&hours, &rate)==2 && fgets(name, sizeof(name), stdin )) { /*this if block prints the column labels for the formatted output on * first run of the while loop only*/ if (count++==0) { printf("\n%-39s %4s%8s%9s\n","name","hours","rate","pay"); } /*this strips the new line character from the name string*/ ptr=strchr(name, '\n'); if (ptr) { *ptr='\0'; } /*this line prints the formatted output to screen, also calculates * the total pay using the hours and pay rate info*/ printf("%-39s %4.2f%8.2f%9.2f\n", name, hours, rate, hours*rate); } return 0; }