Oops, added those values in and I forgot to take them out. And yeah, everything's included. I put it all in beforehand just in case I ever need it. Anyway, I updated the code but there's a small problem with the test:
Code:
class UserInputHandler {
public:
int GetInteger(const int& min, const int& max) {
const std::string invalid_int_("Failure: No integer found.");
const std::string low_int_("Failure: Integer is below minimum value.");
const std::string high_int_("Failure: Integer is above maximum value.");
int result;
std::string line;
std::getline(std::cin, line);
if (getline(std::cin, line)) {
std::stringstream ss(line);
if (ss >> result && ss.eof()) {
if (result < min) {
std::cout << low_int_ << endl;
result = 0;
} else if (result > max) {
std::cout << high_int_ << endl;
result = 0;
}
} else {
std::cout <<invalid_int_ << endl;
result = 0;
}
}
std::cout << "Integer Entered is: " << result << endl;
return result;
}
};
int main() {
UserInputHandler handler;
handler.GetInteger(0,100);
}
The test, however, asks me to input two things for some reason.
Code:
$ ./test
1
2
Integer Entered is: 2
I admit, I should have asked you from the start what these if statements were doing exactly but I was stressing over other problems with the code. But it's better that I understand what's going on, so I'd also like to ask what's happening here.
Code:
if (getline(std::cin, line))
{
std::stringstream ss(line);
if (ss >> result && ss.eof())
{