-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
48 lines (33 loc) · 1.02 KB
/
Utils.cpp
File metadata and controls
48 lines (33 loc) · 1.02 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
#include "Utils.h"
int LimiteEntero(int limi, int limis, int valor) {
if (valor >= limi && valor <= limis)
return valor;
do {
cout << "El valor introducido debe ser entre " << limi << " y " << limis << ": ";
cin >> valor;
skipline(cin);
} while (valor < limi || valor > limis);
return valor;
}
string LimiteCadena(unsigned int limi, unsigned int limis, string valor) {
if (valor.length() >= limi && valor.length() <= limis)
return valor;
do {
cout << "El valor introducido debe tener una longitud entre " << limi << " y " << limis << " caracteres: ";
getline(cin, valor);
} while (valor.length() < limi || valor.length() > limis);
return valor;
}
int Limites(int limi, int limis, string mensaje) {
int dato;
do {
cout << mensaje;
cin >> dato;
skipline(cin);
} while (dato < limi || dato > limis);
return dato;
}
void skipline(std::istream &stream) {
string dummy;
getline(stream, dummy);
}