I am creating a very basic program, which relies upon the user inputting a number (variable) which I have declared as an integer. Because it is an integer the number input needs to be a whole number, and therefore I need to reject decimal numbers with an error message. I thought this would be quite simple. I envisaged the following code would be sufficient:
Unfortunately it's just continuing with the program. Using a breakpoint I have discovered that even if the variable n in put by the user is 4.6 then the value of n just changes to 5 and therefore n is equal to Int(n)!
I can't see why this doesn't work. Any help or advice would be greatly appreciated.
Code:
ElseIf n <> Int(n) Then
Console.WriteLine("Data invalid. Please enter a whole number.")
I can't see why this doesn't work. Any help or advice would be greatly appreciated.