-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputVal.cpp
More file actions
57 lines (43 loc) · 1.84 KB
/
inputVal.cpp
File metadata and controls
57 lines (43 loc) · 1.84 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
/****************************************************************************************************
* * Program name: CS162 Project2
* * Author: Taekyoung Kim
* * Date: 01/21/2019
* * Description: This is inputVal.cpp file for CS162 Project2
* * This function check users' input validation, so if the input is not integer, keeps asking users
* * to input the correct input.
******************************************************************************************************/
#include "inputVal.h"
#include <iostream>
#include <climits>
#include <cctype>
#include <algorithm>
#include "HarryP.h"
#include "Barbarian.h"
#include "BlueMen.h"
#include "Medusa.h"
#include "Vampire.h"
/*********************************************************************
* * This function get double parameter and return an integer value
* * after checking if it is digit and positive number and double.
**********************************************************************/
int inputVal(double in) {
// Check type validation first using std::cin.fail()
if( std::cin.good() && in > 0 && in < 6 && (in - (int)in == 0)) {
return (int)in;
}
else{
do {
//std::cout << "Input" << input << std::endl;
std::cout << "Wrong input! You need to input proper value!" << std::endl;
std::cin.clear();
std::cin.ignore(INT_MAX, '\n');
std::cout << "Please try again. Input here: " << std::endl;
std::cin >> in;
//decimalCheck(input);
} while(!(std::cin.good() && in > 0 && (in - (int)in == 0) ));
}
return (int)in;
}
/********************************************************************************
* * This function get an integer parameter and check if the strength is positive.
******************************************************************************/