Thread: Simple Dart Score Program Not Working Correctly, Help Please.

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    244

    Simple Dart Score Program Not Working Correctly, Help Please.

    Its not adding up the score correctly. Must be a problem with my logic that I can't see b/c I have been trying to figure this out for a while now...

    The instructions for the program is suppose to do is commented in the code.

    Any suggestions will be greatly appreciated.

    thanks in advance.

    Code:
    /*
    40) Write a program that reads a set of dart throws from a user and computes
     the user's score. Assume that the user enters 21 dart throws and each throw
      is a single integer in between 1 and 20, inclusive. To compute the user's 
      score, look at each number in between 15 and 20, inclusive that the user 
      threw more than three times, and add up the points of the throws, after 
      the third throw. For example, if the user throws 5 20s, 3 19s, 4 18s, 6
       14s and 2 1s, then the user's score is 2x20+1x18 = 58, since the user 
    	threw 2 more 20s than 3 and 1 more 18 than 3. The 14s don't count since
    	 only 15 through 20 count for points.
    */
    
    #include <stdio.h>
    
    
    int main(void){
    	
    	
    	int dartScore[23], fifteen=0, sixteen=0, seventeen=0, eighteen=0, nineteen=0, twenty=0, i, sum=0, nothing=0;
    	int totalSum=0, sum1=0, sum2=0, sum3=0, sum4=0, sum5=0, sum6=0;
    
    
    	printf("Please enter your (21) dart throws scores.\n");
    	
    	for(i=0; i < 21; i++){
    		scanf("%d", &dartScore[i]);
    	}
    	
    	for(i=0; i<21; i++){
    			if(dartScore[i]==15){
    				fifteen++;
    			}
    				
    			else if(dartScore[i]==16){
    				sixteen++;
    			}
    			
    			else if(dartScore[i]==17){
    				seventeen++;
    			}
    			else if(dartScore[i]==18){
    				eighteen++;
    			}
    			else if(dartScore[i]==19){
    				nineteen++;
    			}
    			
    			else if(dartScore[i]==20){
    				twenty++;
    			}
    	
    	}
    			printf("fifteen:%d\nsixteen:%d\nseventeen:%d\neighteen:%d\nnineteen:%d\ntwenty:%d.\n", fifteen, sixteen, seventeen, eighteen, nineteen, twenty);
    	
    			if(fifteen > 3)
    				sum1=(fifteen - 3)*15;
    				
    			else if(sixteen > 3)
    				sum2=(sixteen - 3)*16;
    				
    			else if(seventeen > 3)
    				sum3=(seventeen - 3)*17;
    				
    			else if (eighteen > 3)
    				sum4=(eighteen - 3)*18;
    				
    			else if (nineteen > 3)
    				sum5=(nineteen - 3)*19;
    				
    			else if (twenty > 3)
    				sum6=(twenty - 3)*20;
    				
    			totalSum=sum1+sum2+sum3+sum4+sum5+sum6;
    			
    			
    			printf("Your final score is %d.\n", totalSum);
    
    
    system("PAUSE");
    return 0;
    			
    }

  2. #2
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    the third throw. For example, if the user throws 5 20s, 3 19s, 4 18s, 6
    14s and 2 1s, then the user's score is 2x20+1x18 = 58, since the user
    threw 2 more 20s than 3 and 1 more 18 than 3. The 14s don't count since
    only 15 through 20 count for points.
    I could follow up to "if the user throws 5 20s, 3 19s, 4 18s" and then you completely
    lost me.

    I used to enjoy playing darts when I was in college... all we did was try to hit
    the bulls eye. I seemed to get better after a few beers, then I got worse when
    I chased the beers down with a nip or two of Jack Daniels.

    Your statement above lost me... could you post an exact example of a
    score input, and your expected result?

    numbers only and a number for expected output. Also note, your array size seems
    to be a few ints higher than required but not sure.

  3. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    You used else if for the sums... try just using if. Think about it if you have 4 fifteens then the rest of your sums will have no value. So if someone hit 4 fifteens and 10 twenties... you won't caclulate the 7 extra twenties because fifteen was greater than 3. Hope this helps ;o)

    @ char*Pntr
    This is a point keeping method for the common dart game of cricket. Each player attempts to close out 15-20. Close out refers to hitting the numbers 3 times. If you close out 20 and your opponent has not closed out 20 yet then every extra 20 you hit until they close out 20 is added to a point sum. At the end of the game even if the opponent closes all numbers out first, if they don't catch up to you in points before you close everything out then you still win the game. And if they close out first and then beat you in points as well then the game is over and you lose.
    Last edited by Lesshardtofind; 09-25-2010 at 11:39 PM.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  4. #4
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198
    Quote Originally Posted by Lesshardtofind View Post
    You used else if for the sums... try just using if. Think about it if you have 4 fifteens then the rest of your sums will have no value. So if someone hit 4 fifteens and 10 twenties... you won't caclulate the 7 extra twenties because fifteen was greater than 3. Hope this helps ;o)

    @ char*Pntr
    This is a point keeping method for the common dart game of cricket. Each player attempts to close out 15-20. Close out refers to hitting the numbers 3 times. If you close out 20 and your opponent has not closed out 20 yet then every extra 20 you hit until they close out 20 is added to a point sum. At the end of the game even if the opponent closes all numbers out first, if they don't catch up to you in points before you close everything out then you still win the game. And if they close out first and then beat you in points as well then the game is over and you lose.
    Thank you very much for that explanation. I knew that someone would explain to me how the score was kept as darts are played professionally all around the world ( my observation when I was overseas in many European countries while in the Navy)

    Thanks again!

  5. #5
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Lol np.. I've probably spent toooo many drunken nights in the bar throwing my money away playing this game.
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hi, Quiz C program Assignment updated
    By Eman in forum C Programming
    Replies: 19
    Last Post: 11-22-2009, 04:50 PM
  2. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  3. Simple program not working, don't know why
    By Bakster in forum C Programming
    Replies: 11
    Last Post: 01-29-2009, 01:56 PM
  4. Simple window program
    By baniakjr in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2006, 03:46 PM
  5. Help with simple program
    By nik2007 in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2006, 09:54 AM