Question

Write a console application to total a set of numbers indicated and provided by a user,...

Write a console application to total a set of numbers indicated and provided by a user, using a while loop or a do…while loop according to the user’s menu choice as follows:

Example

Menu

1. To total numbers using a while loop

2. To total numbers using a do...while loop

Enter your menu choice: 1

How many numbers do you want to add: 2

Enter a value for number 1: 4

Enter a value for number 2: 5

The total is: 9

Example

Menu

1. To total numbers using a while loop

2. To total numbers using a do...while loop.

Enter your menu choice: 1

How many numbers do you want to add: 4

Enter a value for number 1: 3

Enter a value for number 2: 2

Enter a value for number 3: 5

Enter a value for number 4: 1

The total is: 11

Example

Menu

1. To total numbers using a while loop

2. To total numbers using a do...while loop

Enter your menu choice: 2

How many numbers do you want to add: 2

Enter a value for number 1: 4

Enter a value for number 2: 5

The total is: 9

Example

Menu

1. To total numbers using a while loop

2. To total numbers using a do...while loop.

Enter your menu choice: 2

How many numbers do you want to add: 4

Enter a value for number 1: 3

Enter a value for number 2: 2

Enter a value for number 3: 5

Enter a value for number 4: 1

The total is: 11

Requirements

  1. All the values above are only examples.
  1. Menu choice 1 will total numbers provided by the user using a while loop.
  2. Menu choice 2 will total numbers provided by the user using a do…while loop.
  3. The message “Enter a value for number #” must include a sequence number (i.e. 1, 2, 3, 4, 5, 6, …).

Homework Answers

Answer #1

// Sourcecode.c

#include<stdio.h>

int main(){
printf("Menu\n");
printf("1. To total numbers using a while loop\n");
printf("2. To total numbers using a do...while loop\n");
printf("Enter your menu choice: ");
  
int choice;
scanf("%d",&choice);

if(choice == 1){
int total = 0;
printf("How many numbers do you want to add: ");
int n;
scanf("%d",&n);

int a;
int i=1;
do{
printf("Enter a value for number %d: ",i);
scanf("%d",&a);
total += a;
i++;
}while(i<=n);
printf("The total is: %d",total);

}else if(choice == 2){
int total = 0;
printf("How many numbers do you want to add: ");
int n;
scanf("%d",&n);

int a;
int i=1;
while(i<=n){
printf("Enter a value for number %d: ",i);
scanf("%d",&a);
total += a;
i++;
}
printf("The total is: %d",total);
}
return 0;
}

// Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
WRITE it in Python! how to Write a method named smallest largest that asks the user...
WRITE it in Python! how to Write a method named smallest largest that asks the user to enter numbers, then prints the smallest and largest of all the numbers typed in by the user. You may assume the user enters a valid number greater than 0 for the number of numbers to read. Here is an example dialogue: How many numbers do you want to enter? 4 Number 1: 5 Number 2: 11 Number 3: -2 Number 4: 3 Smallest...
C++ Visual Studio 2019 Write a C++ console application that accepts up to 5 numbers from...
C++ Visual Studio 2019 Write a C++ console application that accepts up to 5 numbers from the user. Display all numbers, the highest, the lowest, and the average of the numbers. Ask the user if they want to continue entering another set of numbers. 1) Use proper naming conventions for your variables and functions. 2) Tell the user what the program is all about. Do NOT start the program with “Enter a number”!! 3) Create an array to store the...
Write a program that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask...
Write a program that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4, end the program....
This program is for kindergartners to practice knowledge on numbers divisible by 5. Write a code...
This program is for kindergartners to practice knowledge on numbers divisible by 5. Write a code using a while loop, which keeps asking the user to enter an number divisible by 5. The program(i.e the while loop) terminates when the user enters a number divisible by 5, but keeps running if the user fails to enter a number divisible by 5. Also print appropriate message after each failed try. When successful, tell the user how many attempts were needed for...
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop...
Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider that your user might give you two of the same...
Write a Python program which calculates the average of the numbers entered by the user through...
Write a Python program which calculates the average of the numbers entered by the user through the keyboard. Use an interactive loop and ask the user at each iteration if he/she wants to enter more numbers. At the end dispay the average on the screen. Using built-in library functions for finding average is not allowed. Sample output of the program: Enter a number > 23 More numbers (yes or no)? y Enter a number > 4 Do you have more...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT