-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcf2.cpp
More file actions
30 lines (30 loc) · 1.01 KB
/
cf2.cpp
File metadata and controls
30 lines (30 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
int main() {
int choice;
// Menu options displayed to the user
cout << "Menu Options:\n";
cout << "1. Print 'Hello'\n";
cout << "2. Print 'World'\n";
cout << "3. Exit\n";
// Start a while loop to keep showing the menu until user exits
while (true) {
cout << "Enter your choice: ";
cin >> choice;
// Switch case statement to handle the menu choices
switch (choice) {
case 1:
cout << "Hello\n";
break; // Exit this case and go back to the menu
case 2:
cout << "World\n";
break; // Exit this case and go back to the menu
case 3:
cout << "Exiting...\n";
return 0; // End the program
default:
cout << "Invalid choice, please try again.\n";
}
}
return 0; // Return 0 if program ends normally (shouldn't reach here in this case)
}