The short version: How can I determine if a value entered by a user and assigned to some variable is an integer value or a double?
The explanation:
This question is related to a homework problem, though not part of the homework.
My assignment is to write a program that asks the user to enter an integer- suppose for now that it's 2- and then uses it to compute a value with this given formula: ((x/3) + (x%3)) * 3.
Then I must output the entire formula and the answer in this format:
"((2/3) + (2%3)) * 3 = 2.000".
This is very basic, I know, but it's the first week of class and it's a beginner's class.
Now, I have finished this assignment already, but something occurred to me: What if the user enters a non-integer value?
I started to plan the program in pseudo-code using an IF-ELSE structure and a WHILE structure to see which makes more sense.
Something like:
IF (the value entered is an integer), then do the calculation.
ELSE, tell the user to try again.
Immediately I ran into the problem of how to determine if the already entered value is an integer or not.
I have looked online and on other fora but no one seems to have a definite answer to this very simple question. And all the answers I've seen involve things that are way beyond my current knowledge.
So, again, a user enters a value and some variable is assigned that value. How do I then determine if they entered an integer or not?