-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.cpp
34 lines (31 loc) · 1.14 KB
/
validate.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
/**********************************************************************************************
* Progam Name: validate.cpp
* Author: George Lenz
* Date: 1/28/2018
* Description: Function to validate integer inputs.
*********************************************************************************************/
#include "validate.hpp"
#include <stdlib.h>
#include <iostream>
using namespace std;
void validate(int* input, int min, int max)
{
do
{
while (!(std::cin >> *input))
{
std::cout << "ERROR: Please enter a valid integer: \n";
std::cin.clear();
std::cin.ignore(500, '\n');
}
std::cin.ignore(500, '\n');
if (*input < min)
{
std::cout << "ERROR: Please enter a number greater than or equal to " << min << endl;
}
else if (*input > max)
{
std::cout << "ERROR: Please enter a number less than or equal to " << max << endl;
}
}while(*input < min || *input > max);
}