Thread: Help required! Bowling Assignment.

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

    Few BUGS

    I have few bugs which i cant locate...driving me nuts...some extra calculations which are completely irrelivant.And thats happening after it reads BART SIMPSON. Also how do i get rid of END OF FILE at the end?

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <time.h>
    #define SENTINAL -1
    
    int
    Tm (void){
    
    time_t t; 
    char now[20];
    time(&t);
    strcpy (now, ctime(&t));
    printf ("%s", now);
    
    return (0);
    }
    
    int
    calc (int sum, int numbers[])
    {
    int i, j;
    i = 0;
    j = 0;
    	while (numbers[i] != -1 && j < 10)
    	{
    
    	if (numbers[i]== 10)
    	{
    		sum = sum + numbers[i] + numbers[i+1] + numbers[i+2];
    		i = i + 1;
    		printf("%3d ", sum);
    	}
    	else if (numbers [i] + numbers[i+1] == 10)
    	{
    		sum = sum + numbers[i] + numbers[i+1] + numbers[i+2];
    		i = i +2;
    		printf("%3d ", sum);
    	}
    	else
    	{
    		sum = sum + numbers[i] + numbers[i+1];
    		i = i + 2;
    		printf("%3d ", sum);
    	}
    
    	}
    ++j;
    	}
    
    void
    print_shots (int numbers[])
    
    {
    int i=0, j;
    j = 0;
    while (numbers[i]!=-1 && j < 10)
    	{
    	if (numbers[i]==10)
    	{
    	printf("   X");
    	++i;
    	}
    	else if (numbers [i]+numbers[i+1]==10)
    	{
    	printf("%5d/",numbers[i]);
    	i=i+2;
    	}
    	else
    	{
    	printf("%5d-%d",numbers[i],numbers[i+1]);
    	i=i+2;
    	} 
    	++j;
    
    }
    }
    
    
    int 
    main (void)
    
    {
    
    FILE *fp;
    char buff[300],end[]= "End of data";
    int numbers[300],count[50],temp, sum;
    int i=0,j;
    temp = 1;
    Tm();
    fp = fopen("c:/bowling.dat", "r");
    
    while 
    (temp !=0)
    
    {
    	fgets(buff, sizeof(buff), fp);
    	printf("\n");
    	i = 0;
    	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);
    	print_shots(numbers);
    	sum = 0;
    	printf("\n");
    	calc(sum, numbers);
    	i = 0;
    
    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] && buff[7]== end[7])
    {
    	temp = 0;
    }
    	fgets(buff, sizeof(buff), fp);
    
    }
    return(0);
    }

  2. #17
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Fix your indentation.
    What compiler are you using? Post up the exact error message as it appears, maybe we can help you further.

    AFAIK Salem isn't banned, it's one of his clever mind games which makes us all feel inferior

    EDIT: Damn, I didn't notice there were 2 pages until I posted (ignore my comment about the error message). I'll have a look through it now. Maybe.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well there seem to be at least 3 people on the board with the same bowling assignment, I wonder if I should post the same solution to all of them.

  4. #19
    Registered User
    Join Date
    Nov 2005
    Posts
    5
    post the assignment tomorrow if you must... but shhh!

    it's due tonight at midnight.

    ~fatty acid

  5. #20
    Registered User
    Join Date
    Nov 2005
    Posts
    9

    Farewell!

    Got the assignment done without ur help!
    You guyz are sitting in front of monitor talking ........!
    Get a life!

  6. #21
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Pacino
    Got the assignment done without ur help!
    You guyz are sitting in front of monitor talking ........!
    Get a life!
    This is one of the saddest, funniest posts I've seen all year.


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

  7. #22
    Registered User KidA's Avatar
    Join Date
    Nov 2005
    Location
    Ohio, USA
    Posts
    26
    Quote Originally Posted by Pacino
    Got the assignment done without ur help!
    You guyz are sitting in front of monitor talking ........!
    Get a life!
    Well that's great! I'm sure it's a fine piece of work.

    So I guess you came a long way in a short period of time - from simply copying and pasting the entire assignment in your initial post to creating a solution on your own - congratulations.
    "So I was sitting in my cubicle today, and I realized, ever since I started working, every single day of my life has been worse than the day before it. So that means that every single day that you see me, that's on the worst day of my life" - Peter Gibbons

  8. #23
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by quzah
    This is one of the saddest, funniest posts I've seen all year.


    Quzah.
    I'm sure I've posted more pathetic & funny posts this year
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

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