-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.cpp
More file actions
81 lines (66 loc) · 1.58 KB
/
Functions.cpp
File metadata and controls
81 lines (66 loc) · 1.58 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <string>
#include "Functions.h"
using namespace std;
// return true if string has spaces
bool stringHasSpace(string str) {
// empty input (enter key pressed without input)
if (str.empty())
{
return true;
}
// whitespaces
for (int i = 0; i < str.length(); i++)
{
if (isspace(str[i]))
{
cout << "*** ERROR: Invalid input. Space(s) detected. ***" << endl;
return true;
}
}
return false;
}
// validates inputs from menu with 2 choices
bool matchMenuInput2(string choice){
if (choice != "1" && choice != "2")
{
cout << "INVALID INPUT. Enter a 1 or 2." << endl;
return false;
}
else if (stringHasSpace(choice))
{
return false;
}
return true;
}
// returns false if string != "y"
bool validateYes(string y)
{
if (y != "y" || stringHasSpace(y))
{
cout << "INVALID INPUT. Enter y (without spaces)." << endl;
return false;
}
return true;
}
// returns false if string != "y" and "n"
bool validateYesNo(string option)
{
if ( (option != "y" && option != "n") || stringHasSpace(option))
{
cout << "INVALID INPUT. Enter y or n (without spaces)." << endl;
return false;
}
return true;
}
/*bool matchRoomType(string type){
if (type != "s" && type != "d" && type != "g"){
cout << "\nINVALID INPUT. Enter s, d, or g without spaces." << endl;
cout << endl;
return false;
}
else if (stringHasSpace(type)) {
return false;
}
return true;
}*/