// Program Favorit determines the favorite soft drink. #include <iostream> using
ID: 3541503 • Letter: #
Question
// Program Favorit determines the favorite soft drink.
#include <iostream>
using namespace std;
enum DrinksType {COKE, PEPSI, SPRITE, DR_PEPPER};
void Prompt();
// This function provides the input prompts.
int main ()
{
int sums[4];
int number;
DrinksType index;
for (index = COKE; index <= DR_PEPPER; index = DrinksType(index+1))
// FILL IN code to set sums to zero
Prompt();
cin >> number;
while (number != 4)
{
// FILL IN code to increment the proper drink
Prompt();
cin >> number;
}
// FILL IN code to write out the totals
return 0;
}
//*******************************************************
void Prompt()
{
cout << "Enter a 0 if your favorite is a Coke." << endl;
cout << "Enter a 1 if your favorite is a Pepsi." << endl;
cout << "Enter a 2 if your favorite is a Sprite." << endl;
cout << "Enter a 3 if your favorite is a Dr. Pepper." << endl;
cout <<"Enter a 4 if you wish to quit the survey." << endl;
}
Exercise 1: Complete program Favorit and run it. Which data did you use? What did
the program write?
Explanation / Answer
#include <iostream>
using namespace std;
enum DrinksType {COKE, PEPSI, SPRITE, DR_PEPPER};
void Prompt();
// This function provides the input prompts.
int main ()
{
int sums[4]={0,0,0,0};
int number;
DrinksType index;
for (index = COKE; index < DR_PEPPER+1; index = DrinksType(index+1))
{
// FILL IN code to set sums to zero
Prompt();
cin >> number;
if (number != 4)
{
// FILL IN code to increment the proper drink
sums[number]=sums[number]+1;
}
}
cout<<"Drink Coke"<<sums[0]<<endl;
cout<<"Drink Pepsi"<<sums[1]<<endl;
cout<<"Drink Sprite"<<sums[2]<<endl;
cout<<"Drink Dr. Pepper."<<sums[3]<<endl;
// FILL IN code to write out the totals
return 0;
}
//*******************************************************
void Prompt()
{
cout << "Enter a 0 if your favorite is a Coke." << endl;
cout << "Enter a 1 if your favorite is a Pepsi." << endl;
cout << "Enter a 2 if your favorite is a Sprite." << endl;
cout << "Enter a 3 if your favorite is a Dr. Pepper." << endl;
cout <<"Enter a 4 if you wish to quit the survey." << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.