-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputVal.cpp
41 lines (30 loc) · 1.21 KB
/
inputVal.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
/****************************************************************************************************
* * Program name: CS162 Group Project
* * Group number: # 29
* * Group member: Taekyoung Kim, Zuhair Ahmed
* * Date: 02/10/2019
* * Description: This is inputVal.cpp file for CS162 GroupProject
* * This project demonstrates a 2D simulation of Predator-Prey Game.
* * The board is a 2D array and each cell points to a Critter.
******************************************************************************************************/
#include "inputVal.h"
#include <iostream>
#include <climits>
int inputVal(double in) {
// Check type validation first using std::cin.fail()
if( std::cin.good() && in > 0 && (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::cin >> in;
//decimalCheck(input);
} while(!(std::cin.good() && in > 0 && (in - (int)in == 0) ));
}
return (int)in;
}