Re: a FOR loop and floating variables

2013-05-02 Thread bearophile
Simen Kjaeraas: Both 5 and 9 in the second example are integers (int). When you divide one int by another, the result is an int, and hence (5/9) is 0. Yes, smarter languages (like Pascal..., but also Python, Ada, etc) have two different division operators to avoid such silly C semantics, th

Re: a FOR loop and floating variables

2013-05-02 Thread Martin DraĊĦar
Dne 2.5.2013 20:14, Carlos napsal(a): I have this code : import std.stdio; import std.c.stdlib; void main() { int fahr; write("F\tC\n"); for (fahr = 0; fahr <= 300; fahr = fahr + 20) write(fahr, "\t", (5.0/9.0)*(fahr-32), "\n"); write("Done!\n"); exit (0); } Which works. but if I change the "5

Re: a FOR loop and floating variables

2013-05-02 Thread Simen Kjaeraas
On 2013-05-02, 20:14, Carlos wrote: I have this code : import std.stdio; import std.c.stdlib; void main() { int fahr; write("F\tC\n"); for (fahr = 0; fahr <= 300; fahr = fahr + 20) write(fahr, "\t", (5.0/9.0)*(fahr-32), "\n"); write("Done!\n"); exit (0); } Which works. but if I change the "5.

a FOR loop and floating variables

2013-05-02 Thread Carlos
I have this code : import std.stdio; import std.c.stdlib; void main() { int fahr; write("F\tC\n"); for (fahr = 0; fahr <= 300; fahr = fahr + 20) write(fahr, "\t", (5.0/9.0)*(fahr-32), "\n"); write("Done!\n"); exit (0); } Which works. but if I change the "5.0" for "5" I get cero on the celsius s