+ 1
How can I do typecasting in 'password'
I created an ATM_System in c++. There is a variable 'password' of type 'int'. If the user enters any string instead of an integer value, the program will keep on running. Is typecasting is its solution? If yes, how can I do it?
7 Antworten
+ 3
Yeah, exactly I want so. I don't know how to share a code link here. Can you please explain?
+ 2
thank you very much
+ 1
Do you want this 'password' to accept only numbers or the other way around? (accepts any character).
Why didn't you share the code link along with the thread Description?
+ 1
To share a code, first you gotta have a copy of the code saved in SoloLearn. And then ...
If you're on mobile, open the code in Playground, tap that share button on top right corner, choose "Copy to clipboard".
If you're on web, open the code in Playground, and copy the URL in the browser's address bar.
Now you have a link to the saved code in clipboard, you can paste it where it is needed. If you paste it in the thread Description people can see it on sight.
I'll be back ...
+ 1
It is rather difficult to actually "force" the input to be in numeric format. I guess the best we could do, for this case (and in console) was to accept the input as string, and then check each character for validity. Or accept input as number and check input stream state after reading input, to see if all went well.