/* File: bonus.c Parse files exported from excel as tab-delimited fields. Assume the columns are: Name integer integer integer White space is not allowed in the names. */ #include #include "primes.h" #define SIZE 100 #define NAME_LENGTH 32 int bonus(int u, int s, int r) ; int main() { char Name[NAME_LENGTH][SIZE] ; int Units[SIZE] ; int Sales[SIZE] ; int Rating[SIZE] ; char Heading1[NAME_LENGTH] ; char Heading2[NAME_LENGTH] ; char Heading3[NAME_LENGTH] ; char Heading4[NAME_LENGTH] ; // Get Headings // Note: spaces between %s are needed to match tabs scanf("%s %s %s %s", Heading1, Heading2, Heading3, Heading4) ; // Read in each row of statistics int r, i, rows ; i = 0 ; while (1) { if (i >= SIZE) { printf("File too big! Recompile with bigger SIZE.\n") ; return 1; } // spaces between %s and %d's match tabs r = scanf("%s %d %d %d", Name[i], &Units[i], &Sales[i], &Rating[i]) ; if (r <= 0) break ; i++ ; } // remember number of rows read rows = i ; // print out table printf("%s\t%s\t%s\t%s\tBonus\n", Heading1, Heading2, Heading3, Heading4) ; for (i = 0 ; i < rows ; i++) { printf("%s\t%d\t%d\t%d", Name[i], Units[i], Sales[i], Rating[i]) ; printf("\t%d\n", bonus(Units[i], Sales[i], Rating[i]) ) ; } return 0 ; } /* Calculate salesperson's bonus using a special recipe. */ int bonus(int u, int s, int r) { return findprime( 6*u + s / (7 * u) + 100 * r ) ; }