Thread: Help required! Bowling Assignment.

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    9

    Help required! Bowling Assignment.

    Hi guys.
    I am here to ask for some help with my assignment. I am taking a C programming course which has no relativity to my field of study, but had no choice than to take it. If i can get some help with my assignment which is due next wednsday would appreciate very much.



    Write a program that reads a data file and uses an array to figure out bowling scores.

    In bowling, 10 pins are set up for each frame and the player gets two chances to knock them down.

    1. If the player knocks down less than 10 ten pins down with the two balls, his/her score for that frame is the total number of pins knocked down.
    2. If the player knocks down all 10 pins with the two balls, it is called a spare and is marked with a "/"). The player gets 10 points plus the number of pins knocked down with the next ball.
    3. If the player knocks down all 10 pins with one ball, it is called a strike and is marked with an "X"). The player gets 10 points plus the number of pins knocked down with the next two balls.

    Frame 10 is a special case. If you get a strike on the first ball you get two extra balls to add-up their scores. If you get a spare with the first two balls then you get a third ball to throw. If you fail to knock down all pins with the first two balls, the game ends there.

    Input data: The data file contains the player’s name and the number of pins knocked down with a ball. -1 indicates the end of the game (the next record is another player name).

    Download the data file at http://www.scs.ryerson.ca/dhamelin/cps118/a/bowling.dat to test your program. Here is another one: bowling2.dat

    For each player, print out the the traditional bowling sheet for that player.
    Print out at the end the name of the winner and your personal and copyright information (see example).
    The output report should be like the following example. This is for only one player; your report must include all players (skip 3 lines between players in the report).
    Your report must use the data from the bowling.dat file but should work with any valid game file.
    __________________________________________________ _
    Program executed on: Actual date and time here*

    Frame 1 2 3 4 5 6 7 8 9 10
    J. Doe X 5/ 6-0 X 0-2 0-1 4-5 4/ 7/ XX9
    Score 20 36 42 54 56 57 66 83 103 132

    . . . other players scores here. . .

    The winner is J. Doe
    Program by: YOUR NAME HERE (STUDENT #) - SECTION 031
    THIS PROGRAM IS MY OWN INDIVIDUAL WORK
    __________________________________________________ _

    How to submit:
    You must submit the following for marking through Blackboard:

    a) A listing of your C program (the .c file).
    b) The output produced by the program using the bowling.dat file in txt format.

    *See this program example to learn how to display the actual date/time in your program.

    Code:
    #include <stdio.h>
    #include <time.h>
    
    int
    main (void){
    
    time_t t; 
    char now[20];
    time(&t);
    strcpy (now, ctime(&t));
    printf ("%s", now);
    
    return (0);
    }

    Here is actual Link:

    Bowling

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > THIS PROGRAM IS MY OWN INDIVIDUAL WORK
    Have all your programs had this?
    Was it ever true?

    In the mean time, read this
    http://cboard.cprogramming.com/annou...ouncementid=39

    Here's a free bone
    Code:
    #include <stdio.h>
    int main ( void ) {
      char buff[BUFSIZ];
      FILE *fp = fopen( "bowling.dat", "r" );
      while ( fgets ( buff, BUFSIZ, fp ) != NULL ) {
        fputs ( buff, stdout );
      }
      fclose ( fp );
      return 0;
    }
    Now work on the "extract information from each line" problem.

    When you've done that, then you can start doing actual work with the data you've extracted.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    9

    Im New To C Programming!

    I do not have a clear picture on how to program, but i am trying my best to undestand what is going on. If you have Biology, Chemistry, Physics and Math on top of the C programming, how does that sound? So i am trying to get some help, i would not be coming here if i did not need help and i am not expecting anyone to do the work for me! Just a little guidence would be appreciated.
    Thank you!

  4. #4
    The Hawk Man
    Join Date
    Nov 2005
    Location
    Beaverton, OR USA
    Posts
    13
    It's a tad difficult to give a person guidance without doing the work for him/her if he/she has never programmed before and has no clue what to do.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Just a little guidence would be appreciated.
    Well make an honest attempt at getting as far as you can instead of ..........ing about how hard life is for you.

    For example "Now work on the "extract information from each line" problem."
    I GAVE you a program which simply reads all the lines in a file, now YOU go read about sscanf(), which can be used to extract information from buff and store the results in other variables. These you can then pass to printf() to make sure you're decoding the file properly.

    If you succeed in this, then move on to the next step.
    If you can't, but have made an attempt, then post it here so we can fix it for you and help you.

    I take it this isn't your FIRST 'C' programming assignment?

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    9
    Buddy....what do u know about life? 1st!
    2nd...we never learned about BUFSIZ...and stop telling me what to do!
    3rd Thanks for UR GENEROSITY! U r very helpful!
    4th...its my second assignment.
    5th...here what i have done so far:
    Code:
    #include <stdio.h>
    
    int main ( void ) 
    {
    	
    	
    	FILE *fp = fopen("bowling.dat", "r" );
    	
    	while ( fgets ( buff, BUFSIZ, fp ) != NULL ) 
    	{
    		fputs ( buff, stdout );
    		
    	}
    
    	fclose ( fp );
      return 0;
    }
    
    int readplayer(FILE *fp)
    {
    	int status = 0;
    	char buff[BUFSIZ];
    	char lastline[] = "End of data";
    	
    	/* Read the 1st line. If EOF, terminate */
    	if (fgets ( buff, BUFSIZ, fp ) == NULL
    	{
    		return -1;
    	}
    	
    	/* Compare to the last line. If last, exit. */
    	if (strncmp(buff, lastline, strlen(lastline) == 0)
    	{
    		return -1;
    	}
    	else
    	{
    		/* Print the Name line (w/o the new line character) */
    		prints("%s", buff);
    		
    		/* Read the 2nd line. If EOF, terminate */
    		if (fgets ( buff, BUFSIZ, fp ) == NULL
    		{
    			return -1;
    		}
    		
    		/* We don't compare to last line, since Name & Score line always go together */

  7. #7
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Professors generally don't assign random assignments. They usually cover the elements needed to fulfill the assignment in class or in other assignments.

    In your recent attempt, you never call readplayer(). You might want to fix that. Consider adding a while loop to call readplayer.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > and stop telling me what to do!
    Deal - go infest some other board with your lazy ass.

  9. #9
    The Hawk Man
    Join Date
    Nov 2005
    Location
    Beaverton, OR USA
    Posts
    13
    I agree with Salem. If you want help, here are few tips:

    1) Be polite.
    2) Use proper spelling and grammar, because if 'U talk lik this', it simply annoys everyone.
    3) Stop yelling (this ties in with 'Be polite' very well).
    4) Try to do the work yourself before asking for help.
    5) Well actually, I can't think of anything else. That is all.

    =Gavin=

  10. #10
    Registered User KidA's Avatar
    Join Date
    Nov 2005
    Location
    Ohio, USA
    Posts
    26
    Pacino,

    Even though you may not be very interested in programming, I am sure you still want to submit your best work and get a good grade on the assignment. That being said, the only way you will be able to solve the problem is to break it down into many small steps and begin to tackle each one. Programming can be too overwhelming otherwise.

    At the very simplest you have the following:

    1. Get the input (read from file to arrays)
    2. Do some processing (calculate the bowling scores)
    3. Perform the output (display results to the screen)

    Each of these points can be further broken down into very manageable functions that you can then begin to code and test on their own. Some should be relatively simple, others more difficult. I think you will find that if you then post a specific question about a specific function you will have more success in getting help.

    Hope this helps...

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    9

    !

    Quote Originally Posted by Salem
    > and stop telling me what to do!
    Deal - go infest some other board with your lazy ass.
    Quite impressive...no wonder you are banned!

  12. #12
    Registered User
    Join Date
    Nov 2005
    Posts
    9
    GavinHawk
    Please YOU too...stop telling me what to do!
    No need for that!

  13. #13
    Registered User
    Join Date
    Nov 2005
    Posts
    9

    Thanks KidA

    Thanks!

    Here is i guess first and third parts:

    Code:
    #include <stdio.h>
    #include <string.h>
    #define SENTINAL -1
    
    
    int
    main (void)
    
    {
    
    FILE *fp;
    char buff[300], end[]= "End of data";
    int numbers[300], temp;
    int i=0;
    temp = 1;
    fp = fopen("c:/quincy/bowling.dat", "r");
    while (temp != 0)
    {
    
    fgets(buff, sizeof(buff), fp);
    printf("%s", buff);
    fscanf(fp,"%d", &numbers[i]);
    while (numbers[i] !=SENTINAL)
    {
    printf("%4d", numbers[i]);
    ++i;
    fscanf(fp,"%d", &numbers[i]);
    
    }
    printf("\n");
    fgets(buff, sizeof(buff), fp);
    
    if (buff[0] == end[0] && buff[1]==end[1] && buff[2] == end[2] && buff[3] == end[3] && buff[4] == end[4] && buff[5] == end[5] && buff[6] == end[6])
    {
    	temp = 0;
    
    }
    }
    
    return(0);
    
    }

  14. #14
    Registered User KidA's Avatar
    Join Date
    Nov 2005
    Location
    Ohio, USA
    Posts
    26
    OK...but do you have a specific question about either part?

    Does the program as you have it so far work as you would expect? If not, what in particular is not working?

    Also, code without at least minor commenting or indentation is rather uninviting...

  15. #15
    Registered User
    Join Date
    Nov 2005
    Posts
    9
    Code:
    /*PartII*/
    
    j=0;
    while(numbers[0] != -1)
    {
    	if (j==0)
    	score[j] = 0;
    	else
    	score[j] = score[j-1];
    
    if (numbers[0] == 10)
    	{
    		printf("x\t");
    		score[j] = score[j]+ 10;
    		fscanf(fp,"%d",&numbers[0]);
    		if(numbers[0] <10)
    		{
    			score[j] = score[j] + numbers[0];
    			fscanf(fp,"%d",&numbers[1]);
    			score[j] = score[j] + numbers[1];
    			printf("%d-%d\t",numbers[0],numbers[1]);
    		}
    		j++;
    
    	}
    else
    	{
    		score[j] = score[j] + numbers[0];
    		fscanf(fp,"%d",&numbers[1]);
    		score[j] = score[j] + numbers[1];
    		if (numbers[1] == -1)
    			break;
    		if ((numbers[0] + numbers[1]) == 10)
    
    		printf("%d/ \t",numbers[0]);
    		else
    		printf("%d-%d\t",numbers[0],numbers[1]);
    
    		j++;
    		}
    fscanf(fp,"%d",&numbers[0]);
    		}
    
    printf("score=/j");
    for(j=0;j<10;j++)
    	{
    	printf("%d\t",score[i]);
    	}

    Something is wrong, says Access violation and some weird calculation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  5. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM