Page 1 of 1

How to read input from user into a double-type variable

Posted: Thu Feb 24, 2011 9:23 pm
by HeinanXP
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,

Re: How to read input from user into a double-type variable

Posted: Fri Feb 25, 2011 11:58 am
by bluemimmosa
double type format specifier is %Ld that means long double..
check here;
http://www.cplusplus.com/reference/clib ... dio/scanf/

Re: How to read input from user into a double-type variable

Posted: Sat Feb 26, 2011 9:41 pm
by HeinanXP
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.

Re: How to read input from user into a double-type variable

Posted: Sun Feb 27, 2011 12:08 pm
by halofreak1990
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