0

What happens if the user entera a different data type than the expected one (for instante a char instead of an int)?

9th Mar 2016, 12:44 AM
Javier Gonzalez
4 odpowiedzi
+ 1
The compiler can't accept the value.
19th Mar 2016, 9:40 PM
Mohamed Ibrahim
Mohamed Ibrahim - avatar
+ 1
Since the "user" is the one who enters the wrong value, the compiler will NOT warn you. The compiler turns your C++ code into object code, then the linker puts all your object code plus any declared dependencies into an executable that the user runs. To cut to the point, YOU have to check if the user's input is what you should accept or not. If you are expecting an int, but the user enters a char, you have to check the value before trying to store their input into a int variable, either using a try catch block or by parsing the input to make sure is just numbers.
12th Jun 2016, 3:30 PM
Andrei Timofte
Andrei Timofte - avatar
+ 1
Use try-catch :-)
13th Jun 2016, 3:26 AM
Khushal Sharma
Khushal Sharma - avatar
0
The compiler is warn you. It will use entered variable`s memory address for expected variable type. So, writen variable will be used expected type.
12th Jun 2016, 10:18 AM
AET