i challenged myself to do a bowling program without using array... but somehow it doesnt seem to be working ;/ can anyone see what is wrong with my program??
Code:
#include <stdio.h>
#include <stdlib.h>
#define FILENAME "data.txt"
int main()
{
int count, throw1, throw2, throw3, nextframethrow1, nextframethrow2, frameScore, totalScore;
int results; //frame, frameScore
int ch;
FILE *fp;
fp = fopen(FILENAME, "r");
if (fp == NULL)
{
printf("Can't open input file, data.txt not found!\n");
exit(1);
}
while ((ch = getc(fp)) != EOF)
{
fgets(fp, "%s", &results);
}
printf(" *\n");
printf(" * BOWLING SCORER *\n");
printf("---------------------------------------------------------------------\n");
printf("Frame No. : 1 2 3 4 5 6 7 8 9 10\n");
printf("---------------------------------------------------------------------\n");
while (results != \n)
{
results=fgetc(fp);
}
printf("Result :");
for (count=1;count<=10;count++)
{
if (throw1==10) //strike
printf("X ");
else if (throw1+throw2==10) //spare
printf("%d // ", throw1);
else //open frame
printf("%d %d ", throw1, throw2);
}
printf("-----------------------------------------------------\n");
nextframethrow1==count++ + throw1;
printf("Frame Score :");
for (count=1;count<=9;count++)
{
if (throw1==0)
printf("%4d", 10+nextframethrow1+nextframethrow2);
else if (throw1+throw2==0)
printf("%4d", 10+nextframethrow1);
else
printf("%4d", throw1+throw2);
}
while (count==10)
{
if (throw1==10 || throw1+throw2==10)
printf("%d", throw1+throw2+throw3); //throw 3 is fillball
else
printf("%d", throw1+throw2)
}
printf("-----------------------------------------------------\n");
printf("Total Score :");
for (count=1;count<=9;count++)
{
totalScore +=(throw1+throw2);
printf("%4d", totalScore);
}
while (count==10)
{
printf("%4d", totalScore+throw1+throw2+throw3);
}
printf("-----------------------------------------------------\n");
fclose(fp);
if (fclose(fp) !=0)
printf("Error in closing file\n");
return 0;
}