0

there is an

int a;

User enters a value but this value should be passed to a function that validates if the user entered an integer or if the user entered something else, without program crash.

cin.good()

will NOT work since it is the variable 'a' which I am passing to the function. Validation should take place inside the function

bool validateInteger(int a)
{
???
}

How to check if a is an integer or not?

user2750830
  • 17
  • 3
  • 12

1 Answers1

4

If you can pass it into your function, it is an int (or has an implicit conversion to int). Otherwise it wouldn't have compiled. So there's no need for validation.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218