[prog] c double/float I/O question
Alice Moomlyn
alice_moomlyn at yahoo.com
Tue Mar 23 13:07:30 EST 2004
#include <stdio.h>
/* This program doesn't do what I expected it to do.
It doesn't seem to be reading the double properly.
What is the correct way to scanf()ion a double?
*/
int main()
{
float myfloat = 23.0;
double mydouble = 42.0;
printf("Printing a float: %f\n", myfloat);
printf("Printing a double: %f\n", mydouble);
printf("Enter a float: ");
scanf("%f", &myfloat);
printf("Enter a double: ");
scanf("%f", &mydouble);
printf("This is the float you entered: %f\n",
myfloat);
printf("This is the double you entered: %f\n",
mydouble);
}
/* Example output:
Printing a float: 23.000000
Printing a double: 42.000000
Enter a float: 5
Enter a double: 2
This is the float you entered: 5.000000
This is the double you entered: 42.000008
*/
=====
"the only way to learn how to be clever is to say stupid things" - anon
__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html
More information about the Programming
mailing list