Untitled Document
Untitled Document
NESTED SWITCH
#include <iostream>
using namespace std;
int main(){
int mainChoice, subChoice;
cout << "Main Menu:\n1. Food\n2. Drinks\n";
cin >> mainChoice;
switch(mainChoice) {
case 1: // Food Menu
cout << "1. Pizza\n2. Burger\n";
cin >> subChoice;
switch(subChoice) {
case 1: cout << "You chose Pizza"; break;
case 2: cout << "You chose Burger"; break;
}
break;
case 2: // Drinks Menu
cout << "1. Coffee\n2. Tea\n";
cin >> subChoice;
switch(subChoice) {
case 1: cout << "You chose Coffee"; break;
case 2: cout << "You chose Tea"; break;
}
break;
}
}
=======================================================
#include <iostream>
using namespace std;
int main() {
char operation;
float number1, number2;
return 0;
}
=============================================
#include <iostream>
#include <string>
int main() {
int choice;
switch (choice) {
case 1: {
cout << "You decided to go left. You encounter a wild beast!" << endl;
cout << "What will you do?" << endl;
cout << "1. Fight the beast" << endl;
cout << "2. Run away" << endl;
cout << "Enter your choice (1 or 2): ";
cin >> choice;
switch (choice) {
case 1:
cout << "You bravely fought the beast and won! You found a treasure
chest!" << endl;
break;
case 2:
cout << "You ran away safely but missed a chance to find treasure."
<< endl;
break;
default:
cout << "Invalid choice! The beast caught you!" << endl;
}
break;
}
case 2: {
cout << "You decided to go right. You find a mysterious cave." << endl;
cout << "What will you do?" << endl;
cout << "1. Enter the cave" << endl;
cout << "2. Stay outside" << endl;
cout << "Enter your choice (1 or 2): ";
cin >> choice;
switch (choice) {
case 1:
cout << "Inside the cave, you find glowing crystals! You are now rich!"
<< endl;
break;
case 2:
cout << "You chose to stay outside, but a dragon appeared! You ran
away!" << endl;
break;
default:
cout << "Invalid choice! A dragon caught you!" << endl;
}
break;
}
default:
cout << "Invalid choice! You are lost in the forest!" << endl;
}
cout << "Thank you for playing the Adventure Game!" << endl;
return 0;
}