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

Write a program that surveys a set of people and tallies their beverage choices

ID: 3621199 • Letter: W

Question

Write a program that surveys a set of people and tallies their beverage choices from the following options:
1.Coffee              2.Tea                       3.Coke                         4.Orange Juice
The progam should input and count each person's choice until a sentinel value of 5 is entered. Once this occurs, the program should display the total number of respondants and the totals for each beverage. The program should validate the user inputs to ensure that only valid numbers(1-5)are entered.

Additional Instructions:
You need to use two nested loops in your program.
- The outer loop checks whether the sentinel value of 5 is entered using a do-while loop.
-Within the outer loop, the inner loop first tests whether the input is valid using a for loop; if the input is invalid, it will repeatedly display the same prompt of "Choice must be between 1 and 5. Please re-enter."until a valid input is entered. And then use a switch statement to increment the corresponding running total for each type of beverage based on the current input.

Sample run:

Program to Tally beverage choices

Enter choice for person #1

(1.coffee   2. Tea    3.Coke    4.Orange Juice   5.Quit Program):2

Enter choice for person#2

(1.coffee   2. Tea    3.Coke    4.Orange Juice   5.Quit Program):3

Enter choice for person #3

(1.coffee   2. Tea    3.Coke    4.Orange Juice   5.Quit Program):4

Enter choice for person #4

(1.coffee   2. Tea    3.Coke    4.Orange Juice   5.Quit Program):4

Enter choice for person #5

(1.coffee   2. Tea    3.Coke    4.Orange Juice   5.Quit Program):1

Enter choice for person #6

(1.coffee   2. Tea    3.Coke    4.Orange Juice   5.Quit Program):2

Enter choice for person #7

(1.coffee   2. Tea    3.Coke    4.Orange Juice   5.Quit Program):0

choice must be between 1 and 5. Please re-enter: 4

Enter choice for person #8

(1.coffee   2. Tea    3.Coke    4.Orange Juice   5.Quit Program):5

The total number of people surveyed is 7. The results are as follows:

Beverage                 Number of votes

****************************************

Coffee                            1

Tea                                 2

Coke                                1

Orange Juice                   3

Explanation / Answer

Hi,
Below is the complete code as per your requirement which is executed and tested using the software Dev C++ V4.9(Please Rate this answer, Thank you)

#include <iostream>
#include <math.h>
#include <stdlib.h>

using namespace std;
main()
{
      int i=1;
      int p=0;
      int coffee=0;
      int tea=0;
      int coke=0;
      int juice=0;
            cout<<"Program to Tally Beverage Choices ";
      do
      {
        for(p=1;i<5;p++)
         {
        cout<<"Menu: "<<"1.coffee "<<"2.Tea "<<"3.Coke "<<"4.Orange Juice "<<"5.Quit ";       
    L: cout<<"Enter choice for person #"<<p<<":";
      cin >> i;
      if(i<=0||i>5)
      {
          cout<<"Please Enter a valid choice ";
          goto L; //lbael
      } //if
   
      switch(i)
          {
                   case 1:
                        coffee++;
                        break;
                   case 2:
                        tea++;
                        break;
                   case 3:
                        coke++;
                        break;
                   case 4:
                        juice++;
                        break;
                   case 5:
                        break;  
                  
                   }
            }//for loop
        
      }//do-while
      while(i>0 && i<5);
      cout<<"The total number of people surveyed is : "<<p -1<<endl;
      cout<<"The Results are: ";
      cout<<"Bevarage        No of Votes ";
      cout<<"****************************"<<endl;
      cout<<"Coffee          "<<coffee<< endl;
      cout<<"Tea             "<<tea<< endl;
      cout<<"Coke            "<<coke<< endl;
      cout<<"Orange Juice    "<<juice<< endl;
      }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote