-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhao.h
79 lines (69 loc) · 2.08 KB
/
hao.h
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
#ifndef HAO_H_INCLUDED
#define HAO_H_INCLUDED
using namespace std;
int getInt(string question)
{
int num; //variable for storing input
do //input loop
{
cout << question << endl; //user interface for retrieving numbers from user
cin >> num;
if(cin.fail()) //test to see if input is valid
{
cout << "Invalid Input Try Harder" << endl; //if not, the program criticizes user
cin.clear(); //clears buffer
cin.ignore(10000,'\n'); //skips the the current characters
}
else
{
cin.clear(); //clears buffer
cin.ignore(10000,'\n'); //skips the the current characters
break; //if no issues it breaks out loop
}
}
while (true); //loops infinitely
return num;
}
int getInt(string question, int lower, int upper) //function for getting input with ranges
{
int num; //variable for storing input
do //input loop
{
cout << question << endl; //user interface for retrieving numbers from user
cin >> num;
cin.clear(); //clears stuff up
cin.ignore(10000,'\n'); //skips the the current characters
if(cin.fail() || num > upper || num < lower) //test to see if input is valid
{
cout << "Invalid Input Try Harder" << endl; //if not, the program criticizes user
cin.clear(); //clears stuff up
cin.ignore(10000,'\n'); //skips the the current characters
}
else break; //if no issues it breaks out loop
}
while (true); //loops infinitely
return num;
}
string getString(string question) //function for getting input with ranges
{
string st; //variable for storing input
cout << question << endl; //user interface for retrieving numbers from user
getline(cin, st);
return st;
}
string changeCase(string st, bool cas)
{
for(int i = 0; i < st.length(); i++)
{
if(cas)
{
st[i] = toupper(st[i]);
}
else
{
st[i] = tolower(st[i]);
}
}
return st;
}
#endif // HAO_H_INCLUDED