+ 2
Char to Int
How i block the user to write a char variable in int variable?becas if i write characteres in variable int, the programang is go to error..(bad english sry)
5 Respostas
+ 5
you could always use a try catch block were an exception occurs this way you can ask the user to input the specifics using the println statement inside the catch block
+ 1
@Timon Thanks, I wasn't sure. I usually cast them anyways for consistency.
0
Although I'm not entirely sure I understand what you're asking.. In C/C++ you shouldn't have any problem storing a char type value inside an int type since it's the same value just stored inside a larger container. You might need a cast first though like so..
int example = (int) 'A';
The cast is where "int" is in parentheses. This tells the compiler to treat the char literal "A" as an int type, thus casting the character into an integer.
If I've misunderstood your question please provide more information and I'll try to help if I can.
0
In this case, you don't need a cast.
0
It sounds like you need user input validation. Before you try to cast you should check the value is within an allowed range.