Here's my complete code so far...
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
// Declare file pointer
FILE *ifp;
int N, i, x;
char fname[50];
printf("Enter filename: ");
scanf("%s", fname);
printf("Opening %s\n", fname);
// Open file
ifp = fopen(fname, "r");
if (ifp == NULL)
{
printf("Error, %s not available\n", fname);
exit(1);
}
// Read N, how many numbers
fscanf( ifp, "%d", &N);
printf("How many is %d\n", N);
// Read the values from the file
int total = 0;
for (i = 0; i < N; ++i)
{
fscanf(ifp, "%d", &x);
printf("%d\n", x);
total = total + x;
printf("The total is: %d\n", total);
}
return 0;
}
Here is the file it is pulling from...It's supposed to represent a bowling score, each set of two numbers representing a frame (the set of three at the end representing the 10th frame).
Code:
21
2
1
4
5
7
6
8
9
2
3
7
5
6
0
1
3
1
6
3
9
8
Now, I have to incorporate STRIKE (10 plus two frames) rules and SPARE(10 plus 1 frame) rules. How would I do that? I've messed around with the for loop below but can't seam to get it to work.
Code:
int total = 0;
for (i = 0; i < N; ++i)
{
fscanf(ifp, "%d", &x);
printf("%d\n", x);
total = total + x;
printf("The total is: %d\n", total);
}