+ 1
if i do not know the kind of input the user will enter what data type do i introduce.
say if i introduce int. and the user enters a decimal. it could affect the code.
12 Answers
+ 7
Which programming language?
+ 4
What program are you trying to write? and please specify a relevant programming language in the tags above.
+ 4
You can take a string variable because it works for all data types and then put some if else to put it to the required data type
+ 4
Hi Manav Roy,
Sorry but it seems your example doesn't work as I tested it.
`auto` type specifier doesn't help for this case. A variable with `auto` type specifier needs an initializer for its value, which is used by the compiler ti deduce a type considered proper for the data.
https://en.cppreference.com/w/cpp/language/auto
+ 2
In python there is no such requirement as there is automatic data type assignment when a variable is Initialized. For languages such as C++ there is "auto" keyword for automatic data type assigning.
+ 1
c++
+ 1
Jojo Emeka an option is to find the int of the input and find out if there is more to the original input minus the int. If so it's a double.
Here is an example
https://code.sololearn.com/chwr4gtF8B3W/?ref=app
0
Manav Roy Just what i needed thanks bro!!