I wrote this program for beverage survey . what are my errors? Here are my instr
ID: 3625300 • Letter: I
Question
I wrote this program for beverage survey . what are my errors? Here are my instructions?
Write a program that performs a survey tally on beverages. The
program should prompt for the next person until a sentinel value of –1 is
entered to terminate the program. Each person participating in the survey
should choose their favorite beverage from the following list:
1. Coffee 2. Tea 3. Coke 4. Orange Juice
Sample Run:
Please input the favorite beverage of person #1: Choose 1, 2, 3, or 4 from the
above menu or -1 to exit the program
4
Please input the favorite beverage of person #2: Choose 1, 2, 3, or 4 from the
above menu or -1 to exit the program
1
Please input the favorite beverage of person #3: Choose 1, 2, 3, or 4 from the
above menu or -1 to exit the program
3
Please input the favorite beverage of person #4: Choose 1, 2, 3, or 4 from the
above menu or -1 to exit the program
1
Please input the favorite beverage of person #5: Choose 1, 2, 3, or 4 from the
above menu or -1 to exit the program
1
Please input the favorite beverage of person #6: Choose 1, 2, 3, or 4 from the
above menu or -1 to exit the program
-1
The total number of people surveyed is 5. The results are as follows:
Beverage Number of Votes
********************************
Coffee 3
Tea 0
Coke 1
Orange Juice
This is what I done , but errors.
#include <iostream>
using namespace std;
int main()
{
int choice;// choose beverages
int c,co,o,t; // four beverages
int total; // total
int person = 1 ; //
cout << " Enter how many person for survey :" ;
cin >> person;
do
{
// display the menu and get a choice
cout << " Beverages Votes ";
cout << "1. Coffee ";
cout << "2. Tea ";
cout << "3. Coke ";
cout << "4. Orange Juice ";
cout << "Please input the favorite beverage of person "<< person << ": Choose 1, 2, 3, or 4 from the
above menu or -1 to exit the program :"
cin >> choice;
// respond to the user's menu selection
switch (choice)
{
case 1 :
c++
break;
case 2 :
t++
break;
case 3 :
co++
break;
case 1 :
o++
break;
}
} while (choice != -1);
// display beverages' votes
cout << "The total number of people surveyed is " << total <<. The results are as follows:" << endl;
cout << " Beverages Votes ";
cout << " ************************************ ";
cout << "1.Coffee "<< c << " ";
cout << "2.Tea "<< t << " ";
cout << "3.CoKe "<< co << " ";
cout << "4.Orange Juice "<< o << " ";
return 0;
}
Explanation / Answer
//Here you go, it should be working fine now. Some of your errors were you had some variables switched and you had two of the same switch statements and various other issues. #include using namespace std; int main() { int choice;// choose beverages int c=0; int co=0; int o=0; int t=0; // four beverages int total=1; int person; // cout > person; do { // display the menu and get a choice coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.