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;
}