Thread: I cant do a bowling programm...

  1. #1
    Registered User
    Join Date
    Aug 2014
    Posts
    8

    I cant do a bowling programm...

    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;
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You should paste your code "as text" to allow the forum software to do syntax highlighting. Also, it would be a good idea to post a sample of the text file your program is supposed to be reading from.

    More importantly, you should be compiling with maximum warnings, and post any compiler warnings/errors you get, along with a brief description of the program and how it's not working.

    Code:
    /*
    main.c||In function 'main':|
    main.c|21|warning: passing argument 1 of 'fgets' from incompatible pointer type|
    stdio.h|353|note: expected 'char *' but argument is of type 'struct FILE *'|
    main.c|21|warning: passing argument 2 of 'fgets' makes integer from pointer without a cast|
    stdio.h|353|note: expected 'int' but argument is of type 'char *'|
    main.c|21|warning: passing argument 3 of 'fgets' from incompatible pointer type|
    stdio.h|353|note: expected 'struct FILE *' but argument is of type 'int *'|
    main.c|30|error: stray '\' in program|
    main.c|30|error: 'n' undeclared (first use in this function)|
    main.c|30|error: (Each undeclared identifier is reported only once|
    main.c|30|error: for each function it appears in.)|
    main.c|46|warning: value computed is not used|
    main.c|63|error: expected ';' before '}' token|
    main.c|7|warning: unused variable 'frameScore'|
    ||=== Build finished: 5 errors, 5 warnings ===|
    */
    The number of types of warnings/errors seem to indicate a lot of code was written before it was compiled. Going forward, you should only be writing a little bit of code at a time, compiling and testing in between. Build up the program piece by piece. See here for an example of this approach: A development process

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bowling Program
    By DuckCowMooQuack in forum C Programming
    Replies: 11
    Last Post: 01-24-2011, 07:14 PM
  2. Need help with a bowling program...
    By fuze in forum C++ Programming
    Replies: 2
    Last Post: 01-11-2008, 04:06 AM
  3. A Different Bowling Program
    By Mike56p in forum C Programming
    Replies: 3
    Last Post: 12-08-2005, 09:47 AM
  4. Bowling again.
    By fatty acid in forum C Programming
    Replies: 4
    Last Post: 11-30-2005, 02:12 AM
  5. Bowling for Columbine
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 97
    Last Post: 09-09-2003, 07:48 PM