I am trying to print the final results of the calculations using my program and put it into a clean organized table for the output, however, when the table is printed it doesn't print properly and I am very lost and my professor isn't really much help. Any help is greatly appreciated thank you!
The table is meant to look like this:
#include <stdio.h>
void main(void) {
float sale[10], pct[10], commission[10];
char emp_name[10][20], company[15];
float sum = 0;
char c;
int i, x, sales_persons, num_of_sales;
printf("Enter your company name: ");
scanf("%s", company);
printf("\nWelcome to the %s Sales Analysis\n", company);
do {
printf("\nEnter how many sales persons from 1 to 10: ");
scanf("%i", &sales_persons);
while ((c = getchar() != '\n') && c != EOF)
; /* clear input buffer */
if (sales_persons < 0 || sales_persons > 10)
printf("Number of sales persons must be 1-10...\n\n");
} while (sales_persons < 0 || sales_persons > 10);
for (x = 0; x < sales_persons; x++) {
printf("\nEnter the name of sales person #%i: ", x + 1);
scanf("%19[^\n]", emp_name[x]);
while ((c = getchar() != '\n') && c != EOF)
;
do {
printf("Enter the number of sales for %s (1 - 20): ", emp_name[x]);
scanf("%i", &num_of_sales);
while ((c = getchar() != '\n') && c != EOF)
; /* clear input buffer */
if (num_of_sales < 0 || num_of_sales > 20)
printf("Number of sales must be 1-20...\n\n");
} while (num_of_sales < 0 || num_of_sales > 20);
do {
printf("Enter the commission percentage for %s (1-50): ", emp_name[x]);
scanf("%f", &pct[x]);
while ((c = getchar() != '\n') && c != EOF)
; /* clear input buffer */
if (pct[x] < 0 || pct[x] > 50) printf("Percent must be 0-50...\n\n");
} while (pct[x] < 0 || pct[x] > 50);
printf("\n");
for (x = 0; x < num_of_sales; x++) {
do {
printf(" Sale #%i for %s: ", x + 1, emp_name[x]);
scanf("%f", &sale[x]);
while ((c = getchar() != '\n') && c != EOF)
; /* clear input buffer */
if (sale[x] < 0) printf("All sales must be greater than 0...\n\n");
} while (sale[x] < 0);
}
sum = sum + sale[x];
commission[x] = pct[x] * sum / 100;
}
printf("\n\n\n *** %s Sales Commission Report ***", company);
printf("\n\n\nName \t\t Sales \t\t Commission");
printf("\n---- \t\t ----- \t\t ----------");
for (x = 0; x < sales_persons; x++) {
printf("\n%s \t\t %.2f\n \t\t%.2f", emp_name[x], sum, commission[x]);
}
getchar();
}