digitalmars.D.learn - problem with doubles
- Michael P. (6/6) Aug 10 2008 So I've attached the file for a very simple program I'm working on.
- Steven Schveighoffer (4/12) Aug 10 2008 scanf is a C function. You need to exactly specify the type in the stri...
- Michael P. (5/24) Aug 10 2008 Thanks, that worked.
- Jarrett Billingsley (7/35) Aug 10 2008 Yes and yes. I really wish the C library were harder to use from D. So...
- Michael P. (2/44) Aug 10 2008 Do you mind giving me an example of using it? For example, reading in an...
- Jarrett Billingsley (3/6) Aug 11 2008 Uh, an example for exactly what you want already exists in the Phobos do...
- Michael P. (3/14) Aug 11 2008 Okay, I'll check,
So I've attached the file for a very simple program I'm working on. The problem comes from past contests questions, see this: http://www.cemc.uwaterloo.ca/ccc/past/previous_contests.shtml The problem I've having is with 2008 Junior problem 1. Every time with my code it says you are overweight, when it is supposed to say normal weight. So I tried printing out the value I was comparing, and it said nan. Anyone know why? -Michael P.
Aug 10 2008
"Michael P." wroteSo I've attached the file for a very simple program I'm working on. The problem comes from past contests questions, see this: http://www.cemc.uwaterloo.ca/ccc/past/previous_contests.shtml The problem I've having is with 2008 Junior problem 1. Every time with my code it says you are overweight, when it is supposed to say normal weight. So I tried printing out the value I was comparing, and it said nan. Anyone know why? -Michael P.scanf is a C function. You need to exactly specify the type in the string, so use %lf for double -Steve
Aug 10 2008
Steven Schveighoffer Wrote:"Michael P." wroteThanks, that worked. BTW, I know that readf is the D equivalent of scanf(right?), but I don't know how to use it. I should be using readf and writef instead of scanf and printf right? -Michael P.So I've attached the file for a very simple program I'm working on. The problem comes from past contests questions, see this: http://www.cemc.uwaterloo.ca/ccc/past/previous_contests.shtml The problem I've having is with 2008 Junior problem 1. Every time with my code it says you are overweight, when it is supposed to say normal weight. So I tried printing out the value I was comparing, and it said nan. Anyone know why? -Michael P.scanf is a C function. You need to exactly specify the type in the string, so use %lf for double -Steve
Aug 10 2008
"Michael P." <baseball.mjp gmail.com> wrote in message news:g7n3i3$bfm$1 digitalmars.com...Steven Schveighoffer Wrote:Yes and yes. I really wish the C library were harder to use from D. So many newcomers end up overusing it and then wonder why they have so many issues. readf is very easy to use. Just like writef and friends, the function knows the type of the argument without having to look at the format string."Michael P." wroteThanks, that worked. BTW, I know that readf is the D equivalent of scanf(right?), but I don't know how to use it. I should be using readf and writef instead of scanf and printf right?So I've attached the file for a very simple program I'm working on. The problem comes from past contests questions, see this: http://www.cemc.uwaterloo.ca/ccc/past/previous_contests.shtml The problem I've having is with 2008 Junior problem 1. Every time with my code it says you are overweight, when it is supposed to say normal weight. So I tried printing out the value I was comparing, and it said nan. Anyone know why? -Michael P.scanf is a C function. You need to exactly specify the type in the string, so use %lf for double -Steve
Aug 10 2008
Jarrett Billingsley Wrote:"Michael P." <baseball.mjp gmail.com> wrote in message news:g7n3i3$bfm$1 digitalmars.com...Do you mind giving me an example of using it? For example, reading in an integer, a string, and a double, in one statement( if possible ) and/or multiple statements?Steven Schveighoffer Wrote:Yes and yes. I really wish the C library were harder to use from D. So many newcomers end up overusing it and then wonder why they have so many issues. readf is very easy to use. Just like writef and friends, the function knows the type of the argument without having to look at the format string."Michael P." wroteThanks, that worked. BTW, I know that readf is the D equivalent of scanf(right?), but I don't know how to use it. I should be using readf and writef instead of scanf and printf right?So I've attached the file for a very simple program I'm working on. The problem comes from past contests questions, see this: http://www.cemc.uwaterloo.ca/ccc/past/previous_contests.shtml The problem I've having is with 2008 Junior problem 1. Every time with my code it says you are overweight, when it is supposed to say normal weight. So I tried printing out the value I was comparing, and it said nan. Anyone know why? -Michael P.scanf is a C function. You need to exactly specify the type in the string, so use %lf for double -Steve
Aug 10 2008
"Michael P." <baseball.mjp gmail.com> wrote in message news:g7o6rk$2pgq$1 digitalmars.com...Do you mind giving me an example of using it? For example, reading in an integer, a string, and a double, in one statement( if possible ) and/or multiple statements?Uh, an example for exactly what you want already exists in the Phobos docs.
Aug 11 2008
Jarrett Billingsley Wrote:"Michael P." <baseball.mjp gmail.com> wrote in message news:g7o6rk$2pgq$1 digitalmars.com...Okay, I'll check, Thanks for the help.Do you mind giving me an example of using it? For example, reading in an integer, a string, and a double, in one statement( if possible ) and/or multiple statements?Uh, an example for exactly what you want already exists in the Phobos docs.
Aug 11 2008