# Simple Dart Score Program Not Working Correctly, Help Please.

Printable View

• 09-25-2010
matthayzon89
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;                         }```
• 09-25-2010
Char*Pntr
Quote:

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. :confused:

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.
• 09-25-2010
Lesshardtofind
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.
• 09-25-2010
Char*Pntr
Quote:

Originally Posted by Lesshardtofind
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!
• 09-25-2010
Lesshardtofind
Lol np.. I've probably spent toooo many drunken nights in the bar throwing my money away playing this game.