# include <stdio.h> int main() ( int number, sum, choice, total_numbers; printf(
ID: 3584761 • Letter: #
Question
# include <stdio.h>
int main()
(
int number, sum, choice, total_numbers;
printf("Welcome to the integer sum program! ");
choice = 0; total numbers = 0; sum = 0;
while (choice != 3)
{
printf("Please enter your choice: ");
scanf("%i", &choice);
if (scanf("%i", &choice)= 1)
printf ("Enter a new integer");
scanf("%i", &number);
else if ( scanf("%i", &choice) = 2)
sum = sum + number ;
else
total_numbers = choice
printf ("So far, You have entered %i numbers", total_numbers);
printf("You may: 1. Enter a new integer 2. Display the current sum 3. Exit ");
}
return 0 ;
}
Information:
At each iteration, the program should print the number of integers that the user has entered
so far, along with a menu describing three possible actions from which the user could choose. The three
possible actions are as follows:
1. Entering a new integer
2. Printing the sum of all the integers entered so far
3. Exiting the program
Explanation / Answer
//tried to match sample run //note that == is comparison and = is equating value # include int main() {//needs to be brace, not parenthesis int number, sum, choice, total_numbers; printf("Welcome to the integer sum program! "); choice = 0; total_numbers = 0; sum = 0; while (choice != 3) { printf ("So far, You have entered %i numbers. ", total_numbers); printf("You may: 1. Enter a new integer 2. Display the current sum 3. Exit "); printf(" Please enter your choice: "); scanf("%i", &choice); ///You scan in choice here if (choice== 1){ ///and start comparing here. ///Note that you need double equal sign for comparison ///Otherwise, you are setting choice equal to 1 here printf ("Enter the new integer: "); scanf("%i", &number); sum = sum + number ; total_numbers++; } else if ( choice== 2){ printf("The current sum is: %d ",sum); } else if(choice!=3){ ///if not 1,2 or 3 printf("You have entered an invalid choice. ");///error message } } return 0 ; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.