Does defining a variable in a loop cause issues when you refer to that variable outside of the loop?
In the following code, it appears to...
Try typing "asd" first.
Then try typing "123.4"
For cout #2 and #3, I get a value of "0".
If I type "123abc" first
Then "123.4"
For cout #2 and #3, I get the first value of "123"
Anyone know why?
Finally, would anyone know of a way to have input checked to see whether it ONLY
contains integers? For example, "1234" would be accepted but "abc1234", "1234abc" or "1234.1" would be rejected? I feel like I am taking an overly complicated route to TRY and achieve this at present ;)
If you declare a variable inside a loop, then you cannot use that variable outside the loop because it is destroyed once you leave the loop. This is great for helping to keep programs smaller since you only use space as you need it.
As for detecting if input is a number or not, you could use cin and that would only accept integers if you put it into an integer, but you also would have the problem that abc1553 would be 1553. If you are using a Window and not a console, you could create and Edit box that doesn't allow these characters, as for consoles, you could just loop until there are only numeric characters in the input.