-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.cpp
59 lines (42 loc) · 1.01 KB
/
functions.cpp
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
/* Functions */
#include "functions.hpp"
#include <iostream>
#include <limits>
int getIntInput() {
int i;
std::cin >> i;
while(1) {
if(!std::cin) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Something went wrong, please try again!" << std::endl;
std::cin >> i;
}
if(std::cin)
break;
}
return i;
}
double getDoubleInput() {
double d;
std::cin >> d;
while(1) {
if(!std::cin) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Something went wrong, please try again!" << std::endl;
std::cin >> d;
}
if(std::cin)
break;
}
return d;
}
std::string getStringInput() {
std::string s;
std::cin >> s;
return s;
}
void print(std::string text) {
std::cout << text << "\n";
}