A Different Bowling Program

This is a discussion on A Different Bowling Program within the C Programming forums, part of the General Programming Boards category; I am trying to create a C program to calculate bowling scores (this is not the same as the other ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    A Different Bowling Program

    I am trying to create a C program to calculate bowling scores (this is not the same as the other bowling problems posted here). I am having trouble figuring out where to go when a strike is encountered without using 1000 if statements. I would greatly appreciate any help i can get with either logic or code.

    Here is a stripped down version of my code (no fancy display), it contains only the scoring functions. I have heard that a struct or a flag might help me, but i am not very familiar with them yet so i am heading to look them up now. Again, any help would be greatly appreciated. Thanks.

    Code:
    #include "stdio.h"
    #include "stdlib.h"
    #include "string.h"
    #include "math.h"
    
    int main(void)
    {
      FILE *fp;
      char c; 
      int i = 0;
      int j = 0;
      int players = 0;
      int frame[10][2];
      int total_score = 0;
      char strike_answer;
      char spare_answer;
        
       for(i = 0; i<10; i++)
       {
           for( j = 0; j<2; j++)
           {
               if( j == 0)
               {
                   printf("Did You get a strike? y/n?");
                   strike_answer = getc(stdin);
                   fflush(stdin);
                   
                   if(strike_answer == 'y')
                   {
                       printf("STRIKE!!!\n");
                       j = j+2;
                       // strike function                                                            
                   }
                   else
                   {                  
                       printf("Enter Score for Frame %i Ball %i\n", i+1,j+1);
                       scanf("%i", &frame[i][j]); 
                       fflush(stdin);     
                       total_score = total_score + frame[i][j];    
                       printf("Total Score is %i\n", total_score);  
                   }  
               }
               if(j == 1)
               {
                   printf("Did You get a spare? y/n?");
                   spare_answer = getc(stdin);
                   fflush(stdin);
                   
                   if(spare_answer == 'y')
                   {
                      printf("spare\n");
                      // spare function
                   }
                   else
                   {
                       printf("Enter Score for Frame %i Ball %i\n", i+1,j+1);
                       scanf("%i", &frame[i][j]); 
                       fflush(stdin);     
                       total_score = total_score + frame[i][j];    
                       printf("Total Score is %i\n", total_score);    
                   }                       
               }
           }    
       }        
        system("pause");
        return(0);

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    Code:
    fflush(stdin);
    X strike one

  3. #3
    Logic Junkie
    Join Date
    Nov 2005
    Posts
    31
    Yes indeed, fflush() is undefined on input buffers.

    But I don't entirely see where you would need many if-elses in the case of a strike. You should tell us what you intent to happen after a strike, then we might be able to clue you in.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by sand_man
    Code:
    fflush(stdin);
    X strike one
    You're confusing bowling with baseball. In bowling it's good to get a strike.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a bowling program...
    By fuze in forum C++ Programming
    Replies: 2
    Last Post: 01-11-2008, 04:06 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21