Re: I'm getting NAN out of nowhere

2017-04-10 Thread Binarydepth via Digitalmars-d-learn
On Monday, 13 July 2015 at 14:29:57 UTC, Steven Schveighoffer wrote: On 7/11/15 12:57 PM, flamencofantasy wrote: On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: This is my code : import std.stdio : writeln, readf; void main(){ int[3] nums; float prom; foreach(nem; 0

Re: I'm getting NAN out of nowhere

2017-04-10 Thread Binarydepth via Digitalmars-d-learn
On Saturday, 11 July 2015 at 16:57:55 UTC, flamencofantasy wrote: On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: This is my code : import std.stdio : writeln, readf; void main() { int[3] nums; float prom; foreach(nem; 0..2) { writeln

Re: I'm getting NAN out of nowhere

2015-07-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/11/15 12:57 PM, flamencofantasy wrote: On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: This is my code : import std.stdio : writeln, readf; void main(){ int[3] nums; float prom; foreach(nem; 0..2){ writeln("input a number : "); readf(" %d", &

Re: I'm getting NAN out of nowhere

2015-07-11 Thread flamencofantasy via Digitalmars-d-learn
On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: This is my code : import std.stdio : writeln, readf; void main() { int[3] nums; float prom; foreach(nem; 0..2) { writeln("input a number : "); readf(" %d", &nums[nem]);

Re: I'm getting NAN out of nowhere

2015-07-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/9/15 1:04 PM, bachmeier wrote: On Thursday, 9 July 2015 at 15:18:18 UTC, Adam D. Ruppe wrote: On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: float prom; You didn't initialize this variable. Set it to 0.0 and it will work. Like how pointers are initialized to null autom

Re: I'm getting NAN out of nowhere

2015-07-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 9 July 2015 at 17:04:43 UTC, bachmeier wrote: Is there a reason the compiler doesn't identify this as an error? The compiler just doesn't really try to trace if variables have actually been initialized or not. It punts it to runtime for simplicity of compiler implementation.

Re: I'm getting NAN out of nowhere

2015-07-09 Thread bachmeier via Digitalmars-d-learn
On Thursday, 9 July 2015 at 15:18:18 UTC, Adam D. Ruppe wrote: On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: float prom; You didn't initialize this variable. Set it to 0.0 and it will work. Like how pointers are initialized to null automatically in D, floats are auto

Re: I'm getting NAN out of nowhere

2015-07-09 Thread Binarydepth via Digitalmars-d-learn
On Thursday, 9 July 2015 at 15:18:18 UTC, Adam D. Ruppe wrote: On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: float prom; You didn't initialize this variable. Set it to 0.0 and it will work. Like how pointers are initialized to null automatically in D, floats are auto

Re: I'm getting NAN out of nowhere

2015-07-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 9 July 2015 at 15:14:43 UTC, Binarydepth wrote: float prom; You didn't initialize this variable. Set it to 0.0 and it will work. Like how pointers are initialized to null automatically in D, floats are auto initalized to NaN in D. The idea is to make use of an uninitia

I'm getting NAN out of nowhere

2015-07-09 Thread Binarydepth via Digitalmars-d-learn
This is my code : import std.stdio : writeln, readf; void main() { int[3] nums; float prom; foreach(nem; 0..2) { writeln("input a number : "); readf(" %d", &nums[nem]); prom+=nums[nem]; } writeln(prom/