-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputValidation.cpp
More file actions
79 lines (66 loc) · 2.38 KB
/
inputValidation.cpp
File metadata and controls
79 lines (66 loc) · 2.38 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
/*******************************************************************************
* ** Author: Gavin Slusher
* ** Date: 4/8/2019
* ** Description: Input validation file. Contains a functions to validate
* ** different number types.
* **
* ** Currently contains two functions to validate an integer,
* ** and a double
* ** *************************************************************************/
#include <iostream>
#include <string>
#include <limits>
#include "inputValidation.hpp"
using std::cout;
using std::cin;
using std::endl;
/*******************************************************************************
* bool validatePosInt(int num, const int MAX_INT, const int MIN_INT)
* Function to validate an integer based off user-defined maximums and
* minimums. This validation function assumes that the input is definitely
* an integer, so it should be used in tandem with another validation
* function that rejects other kinds of input.
*******************************************************************************/
bool validateInt(int num, const int MAX_INT, const int MIN_INT)
{
bool valid;
valid = true;
if (num > MAX_INT)
{
valid = false;
cout << "That number is too big. ";
}
if (num < MIN_INT)
{
valid = false;
cout << "That number is too small. ";
}
if (!valid)
cout << "Not a valid entry." << endl;
return valid;
}
/*******************************************************************************
* bool validateDouble(double num, const double MAX_INT, double int MIN_INT)
* Function to validate an double based off user-defined maximums and
* minimums. This validation function assumes that the input is definitely
* an double, so it should be used in tandem with another validation
* function that rejects other kinds of input.
*******************************************************************************/
bool validateDouble(double num, const double MAX_INT, const double MIN_INT)
{
bool valid;
valid = true;
if (num > MAX_INT)
{
valid = false;
cout << "That number is too big. ";
}
if (num < MIN_INT)
{
valid = false;
cout << "That number is too small. ";
}
if (!valid)
cout << "Not a valid entry." << endl;
return valid;
}