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

This code will not let me enter all three numbers to output a sum. What is the p

ID: 3881833 • Letter: T

Question

This code will not let me enter all three numbers to output a sum. What is the problem here?

#include <stdio.h>

int main()

{

        int count;

printf("Enter the number 1 or 0 for the count:"); //prompt

        scanf_s("%d", &count);

while (count >= 0)

                {

                        switch (count)

                        {

                case 0:

                        printf(" %d is the number you entered ", count);

                        break;

case 1:

                        printf(" %d is the number you entered ", count);

default:

                        printf(" Incorrect input - You did not enter a 1 or 0 ");

                        break;

}

                printf("Enter the number 1 or 0 for the count:"); //Input another count  

                scanf_s("%d", &count);

}

return 0;

}

Explanation / Answer

int main()

{

        int count;

printf("Enter the number 1 or 0 for the count:"); //prompt

        scanf("%d", &count);

while (count >= 0)

                {

                        switch (count)

                        {

                case 0:

                        printf(" %d is the number you entered ", count);

                        break;

case 1:

                        printf(" %d is the number you entered ", count);

break; // here break is missing.

default:

                        printf(" Incorrect input - You did not enter a 1 or 0 ");

                        break;

}

                printf("Enter the number 1 or 0 for the count:"); //Input another count  

                scanf("%d", &count);

}

return 0;

}

Sample Output::-

Enter the number 1 or 0 for the count:0

0 is the number you entered

Enter the number 1 or 0 for the count:1

1 is the number you entered

Enter the number 1 or 0 for the count:4


Incorrect input - You did not enter a 1 or 0

Note::- I think break is missing in case:1 because of that Its not taking all three input. now its working with all three input.