Can someone PLEASE help me with fixing this. Something is wrong with how the strikes are being added, it seems to just add 10. The numbers in the file are: 8 1 9 1 7 2 10 8 2 6 2 7 3 10 10 10 8 1. I'm also getting 12 frames instead of 12. The total score is supposed to be 176 and I get 153.
Code:
#include <stdio.h>
#include <stdlib.h>
//prototypes (function announcement)
//function main
int main ()
{
// declarations and initializations
int balls [21]={0};
int frame [11]={0};
frame [0]=0;
int j=1;
int index=0;
int Fscore=0;
// int TotalScore =0;
FILE * frData;
//prompts and scans
frData=fopen("CleanLane9.txt", "r");
if (!frData)
{
printf("could not open file\a\n");
exit (101);
}
// calculation
do
{
fscanf(frData, "%d", &balls[index]);
//printf("%d ", balls [index]);
index+=1;
}
while ( (fscanf(frData, "%c", &Fscore))!=EOF);
index=0;
for (; index<=21;)
{
if ((balls[index])==10)
{
frame[j]=frame[j-1]+balls[index]+balls[index+1]+balls[index+2];
printf("\nFrame %d: %d\n ", j,frame[j]);
index++;
j++;
}
else if ((balls[index]+balls[index+1])==10)
{
frame[j]=frame[j-1]+balls[index]+balls[index+1]+balls[index+2];
printf("\nFrame %d: %d\n ", j,frame[j]);
index+=2;
j++;
}
else ((balls[index])<10);
{
frame[j] = frame[j-1]+balls[index]+balls[index+1];
printf("\nFrame %d: %d\n ", j,frame[j]);
index+=2;
j++;
}
}
// output
return 0;
}
// more functions