-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestMenu.cpp
More file actions
36 lines (28 loc) · 901 Bytes
/
testMenu.cpp
File metadata and controls
36 lines (28 loc) · 901 Bytes
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
31
32
33
34
35
36
#include <iostream>
#include <string>
using namespace std;
// checks if inputs with spaces, special characters, empty inputs, etc. are rejected for a menu with 2 options
// function combined in Functions.h called matchMenuInput2()
int main(){
// ask for choice
string choice;
cout << "Enter your option (1 or 2): ";
getline(cin, choice);
// checks if choice isn't a 1 or 2
if ( (choice != "1" && choice != "2") || choice.empty()){
cout << "INVALID INPUT. Enter a 1 or 2." << endl;
cout << endl;
return 0;
}
// checks if choice contains any spaces
else {
for (int i = 0; i < choice.length(); i++) {
if (isspace(choice[i])) {
cout << "INVALID INPUT. Enter a 1 or 2." << endl;
cout << endl;
return 0;
}
}
}
cout << "Successful." << endl;
}