6.5 Bowling program |
At the beginning of your program printout the following:
Your input data will be:
For each game print out all ten frames. For each frame print out the following:
Name: John Doe Frame 1: Ball 1: 10 Ball 2: none Strike Score: 20 Frame 2: Ball 1: 5 Ball 2: 5 Spare Score: 36 Frame 3: Ball 1: 6 Ball 2: 0 Score: 42 Frame 4: Ball 1: 10 Ball 2: none Strike Score: 54 Frame 5: Ball 1: 0 Ball 2: 2 Score: 56 Frame 6: Ball 1: 0 Ball 2: 1 Score: 57 Frame 7: Ball 1: 4 Ball 2: 5 Score: 66 Frame 8: Ball 1: 4 Ball 2: 6 Spare Score: 83 Frame 9: Ball 1: 7 Ball 2: 3 Spare Score: 103 Frame 10: Ball 1: 10 Ball 2: none Strike Score: 133 Extra Ball 1: 10 Extra Ball 2: 10You will also need to print out your results using the "traditional" format for a bowling score sheet.
Name: John Doe ( Error message will go here -- if there are any ) ___1___2___3___4___5___6___7___8___9__10___ | |X|5|/|6|0| |X|0|2|0|1|4|5|4|/|7|/|X|X|X| | 20| 36| 42| 54| 56| 57| 66| 83|103| 133| -------------------------------------------Remember that after the last frame, up to two additional balls may be played. (Two for a strike and one for a spare.) Your program also needs to check for errors in the input data: The types of errors your program needs to look for are:
The second one has lots of errors, to check your error handling code.
It is available by anonymous FTP at
ftp://lt.tucson.az.us/pub/c/bwerror.dat.
An example program for reading the data file is available at:
ftp://lt.tucson.az.us/pub/c/read-bowling.c
Here is the example program:
/* Louis Taber 3/26/2001 * * -- Read bowling info * * Third example program for fscanf() * example of fscanf, errno, perror * */ #include <stdio.h> #include <errno.h> #define TRUE 1 int extern errno; int main(int argc, char *argv[]) { FILE *fp; int score; int balls; char bowler[200]; char blanks[200]; if( argc == 1 ) /* No arguments -- use std input */ { fp= stdin; } else { if((fp = fopen( argv[1], "r")) == NULL) { printf(" Error(%d): %s\n", errno, strerror(errno)); printf("%s(line %d): fopen error: %s\n", __FILE__, __LINE__, argv[1]); return 1; } } while( TRUE ) { fgets(bowler, sizeof(bowler), fp); balls = 0; while( TRUE ) { fscanf(fp, "%d", &score ); if( score < 0 ) break; balls ++; printf(" %02d", score); } fgets(blanks, sizeof(blanks), fp); printf("\nballs: %4d %s\n", balls, bowler); if( score == -2 ) break; } fclose(fp); return 0; }
Mark your output two printouts and your listing with:
6.5 Bowling program |