Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fix this code to account for illegal inputs (bowling scores) and just make it lo

ID: 3572572 • Letter: F

Question

Fix this code to account for illegal inputs (bowling scores) and just make it look cleaner. In C

Code:

#include <stdio.h>
#define True 1
#define False 0

int main()
{
int roll_1, roll_2, roll_3, sum, count, true, false;
int strike = false, spare = false;
count = 1;
sum = 0;
roll_1 = 0;
roll_2 = 0;

do
{
printf("Enter roll 1 of frame ");
scanf("%d",&roll_1);
if (roll_1 == 10)
{
printf("Nice strike! ");
strike = False;
sum = sum + 10;
printf("%d",sum);

}
else if (roll_1 <= 10)
{
printf("Enter roll 2 of frame ");
scanf("%d",&roll_2);
if (roll_1 + roll_2 == 10)
{
printf("Nice spare! ");
spare = False;
sum = sum + roll_1 + roll_2;
printf("%d ",sum);

}
else if (roll_1 + roll_2 > 10)
{
do
{
printf("Enter roll 2 of frame ");
scanf("%d",&roll_2);
}
while (roll_1 + roll_2 > 10);
}
else
{
sum = sum + roll_1 + roll_2;
printf("%d ",sum);

}
}
else
{
printf("Enter roll 2 of frame ");
scanf("%d",&roll_2);
if (roll_1 + roll_2 == 10)
{
printf("Nice spare! ");
}
sum = sum + roll_1 + roll_2;
printf("%d ",sum);

}

if(strike == False)
{
printf("%d",sum);
sum = sum + 10 + roll_1;
}

else if(spare == False)
{
printf("%d ",sum);
sum = sum + roll_1; //+ throw_2;
}


if(sum == 300)
{
printf("You bowled a perfect game!");
}

if (count >= 10)
{
printf(" %d ", sum);
}
++count;
}
while (count <= 10);


return(0);
}

Explanation / Answer

output: