//Users favorite drink survey // Program using one dimensional arrays with enum
ID: 659658 • Letter: #
Question
//Users favorite drink survey
// Program using one dimensional arrays with enum indexes
#include <iostream>
using namespace std;
enum Drinks {COKE, PEPSI, SPRITE, DR_PEPPER};
void Prompt();
int main ()
{
int favorites[4]; //holds sum of users who favor each drink
int number;
Drinks index;
for (index = COKE; index <= DR_PEPPER; index = Drinks(index+1))
// FILL IN Code to initialize array favorites to all zeros
Prompt();
cin >> number;
while (number != 4)
{
// FILL IN Code to increment the proper drink fvorites based on user selections
// e.g. if user enter 0 increment favorites[COKE] etc.
Prompt();
cin >> number;
}
// FILL IN THE Code to write out the totals in the format:
// Drink Number of favorites
system(
Explanation / Answer
//Users favorite drink survey
// Program using one dimensional arrays with enum indexes
#include <iostream>
#include <cstdlib>
using namespace std;
enum Drinks {COKE, PEPSI, SPRITE, DR_PEPPER};
void Prompt();
void percentageDrinks(int []);
int main ()
{
int favorites[4]; //holds sum of users who favor each drink
int number;
Drinks index;
for (index = COKE; index <= DR_PEPPER; index = Drinks(index+1))
// FILL IN Code to initialize array favorites to all zeros
favorites[index]=0; //My Added code for initialization of all zeros
Prompt();
cin >> number;
while (number != 4)
{
// FILL IN Code to increment the proper drink fvorites based on user selections
// e.g. if user enter 0 increment favorites[COKE] etc.
//This is my code added to check each prompt value and increment respective favorite drink
switch(number)
{
case 0:
favorites[COKE]++;
break;
case 1:
favorites[PEPSI]++;
break;
case 2:
favorites[SPRITE]++;
break;
case 3:
favorites[DR_PEPPER]++;
break;
case 4:
cout<<" Bye...";
break;
}
Prompt();
cin >> number;
}
//End of switch case
// FILL IN THE Code to write out the totals in the format:
// Drink Number of favorites
percentageDrinks(favorites);//Calling of function defined below
//system(
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.