I have a bowling program that runs right now with numbers. I want to change spares and strikes to /s and Xs. How would you go about handling this problem? Where should I start?
Below is the bowling program...
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *ifp;
int N, x;
char fname[21];
printf("Enter the filename: ");
scanf("%s", fname);
//Open
ifp = fopen(fname, "r");
//If no file
if (ifp == NULL)
{
printf("Error, %s not available\n", fname);
exit(1);
}
int scores[22];
int i, y;
//Array storage
for(i = 0; i<22; ++i)
{
fscanf( ifp, "%d", &y);
if(y == -1)
{
scores[i] = y;
break;
}
scores[i] = y;
}
int howmany;
howmany = i;
//Prints SUM
i = 0;
int c=0;
while(scores[i] != -1)
{
c = scores[i] + c;
++i;
}
printf("SUM: %d\n\n",c);
printf("N = %d\n", howmany);
printf("----------------------\n");
int f,e,total;
y = 0;
e = 0;
total = 0;
//Scores total with strike, spare rules
for (y=0;y<22;y++)
{
if(scores[e] == 10)
{
total = total + 10 + scores[e+1] + scores[e+2];
printf("Frame %2d: Total %2d\n",y+1, total);
e = e + 1;
printf("STRIKE!\n");
}
else if(scores[e] + scores[e+1] == 10)
{
total = total + 10 + scores[e+2];
printf("Frame %2d: Total %2d\n",y+1, total);
e = e + 2;
printf("SPARE!\n");
}
else if(scores[e] == -1)
{
printf("----------------------\n");
printf("Your final score is: %2d", total);
break;
}
else
{
total = total + scores[e] + scores[e+1];
printf("Frame %2d: Total %2d\n",y+1, total);
e = e + 2;
}
}
return 0;
}
And here is the file the program reads from...
Code:
10 10 10 1 0 1 9 2 2 1 6 3 2 10 1 2 -1