Hey,
I am trying to read input from the user and put it inside a double-type variable?
I developed a function who does the sqrt function to a number, the problem is that I can't read any double-type input from the user, only int-type.
Does anybody knows how to write such a function that will enable me to read input from the user and put it inside a double-type variable?
Thanks in advance,
How to read input from user into a double-type variable
Moderator:Moderators
-
- Posts:3
- Joined:Fri Feb 18, 2011 5:10 am
Re: How to read input from user into a double-type variable
double type format specifier is %Ld that means long double..
check here;
http://www.cplusplus.com/reference/clib ... dio/scanf/
check here;
http://www.cplusplus.com/reference/clib ... dio/scanf/
Re: How to read input from user into a double-type variable
That could be helpful if I could use Microsoft C++ libraries, but, since I can't, I am looking for a way to actually write a function that will allow me to take a string, and put inside a double variable.
-
- Posts:92
- Joined:Thu May 27, 2010 8:54 pm
- Location:Netherlands
Re: How to read input from user into a double-type variable
The easiest way to get what you want would be to search online for an implementation of strtod (string to double) it's somewhere in the C library.
I've heard the Microsoft C library source code is supplied with each Visual C++ compiler, so you could take a look at it.
As long as it's written in plain C or C++, it's just a matter of copy-pasting to get it to work for you.
see http://www.cplusplus.com/reference/clib ... ib/strtod/ for more information about strtod
I've heard the Microsoft C library source code is supplied with each Visual C++ compiler, so you could take a look at it.
As long as it's written in plain C or C++, it's just a matter of copy-pasting to get it to work for you.
see http://www.cplusplus.com/reference/clib ... ib/strtod/ for more information about strtod