Menu

Beverage Choices

With Switch 

#include <iostream>

using namespace std;

int main()
{
int choice;
// Choices menu
cout << "Choose your beverage:" << endl;
cout << "1. Pepsi" << endl;
cout << "2. Mountain Dew" << endl;
cout << "3. Sprite" << endl;
cout << "4. Fanta" << endl;
cout << "5. Coca Cola" << endl << endl;

 

// Switch statement to handle user's choice

cout << "Enter your choice: " <<endl << endl;
cin >> choice;
switch (choice){
case '1': {
cout << "You have chosen Pespi." << endl << endl;
break;
}
case 2: {
cout << "You have chosen Mountain Dew." << endl << endl;
break;
}
case 3:{
cout << " You have chosen Sprite." << endl << endl;
break;
}
case 4: {
cout << "You have chosen Fanta." << endl << endl;
break;
}
case 5: {
cout << "You have chosen Coca Cola." << endl << endl;
break;
}

default:
cout << "Error: Choice was not valid, here is your money back." << endl << endl;
}
return 0;
}

 

With if Statement

#include <iostream>

using namespace std;

int main()
{
int choice;
//Choices menu
cout << "1.) Pepsi" << endl;
cout << "2.) Mountain Dew" << endl;
cout << "3.) Sprite" << endl;
cout << "4.) Fanta" << endl;
cout << "5.) Coca Cola" << endl;

//Prompts user for chosen beverage
cout << endl << endl << "Enter a choice: " << endl;
cin >> choice;

 

//if statements for valid choice
if (choice == 1){
cout << "You have chosen Pespi" << endl;

}

else if (choice == 2){
cout << "You have chosen Mountain Dew" <<endl;
}

else if (choice == 3){
cout << "You have chosen Sprite" << endl;
}

else if (choice == 4){
cout << "You have chosen Fanta" << endl;
}
else if (choice == 5) {
cout << "You have chosen Coca Cola" << endl;
}

else if (!choice!=1-5) {
cout << "Error: choice was not valid, here is your money back." << endl;

}


return 0;
}