|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I copied this code from page 9 k&r 2 and it gives an error that even I
can see. Celsius is uninialized. /* code */ #include <stdio.h> main(){ int fahr,celsius,lower,upper,step; lower=0; upper=300; step=20; fahr=lower; while (fahr<=upper) {celsius=5*(fahr-32)/9; printf("%d\t%d\n",fahr,celsuis; fahr=farh+step;}} /*end*/ Celsius is intialized within the body of the while function. Why is this code from k&r2 not working? Bill |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
In article <b9l2j.29168$Xg.23657@trnddc06>,
Bill Cunningham <some@net.com> wrote: > I copied this code from page 9 k&r 2 and it gives an error that even I >can see. Celsius is uninialized. >/* code */ >#include <stdio.h> > >main(){ > int fahr,celsius,lower,upper,step; > lower=0; > upper=300; > step=20; > fahr=lower; > while (fahr<=upper) > {celsius=5*(fahr-32)/9; > printf("%d\t%d\n",fahr,celsuis; Did you notice the misspelling of celsius on the above line? > fahr=farh+step;}} > >/*end*/ -- "No one has the right to destroy another person's belief by demanding empirical evidence." -- Ann Landers |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Bill Cunningham wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I > can see. Celsius is uninialized. > > /* code */ > > #include <stdio.h> > > main(){ > int fahr,celsius,lower,upper,step; > lower=0; > upper=300; > step=20; > fahr=lower; > while (fahr<=upper) > {celsius=5*(fahr-32)/9; > printf("%d\t%d\n",fahr,celsuis; > fahr=farh+step;}} > > /*end*/ > > Celsius is intialized within the body of the while function. Why is this > code from k&r2 not working? You should read the message again. Isn't it rather "celsuis is undefined"? celsuis? And did you get something about "farh"? |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca> wrote in message news:ficn3p$4rh$1@canopus.cc.umanitoba.ca... > In article <b9l2j.29168$Xg.23657@trnddc06>, > Bill Cunningham <some@net.com> wrote: >> I copied this code from page 9 k&r 2 and it gives an error that even I >>can see. Celsius is uninialized. > >>/* code */ > >>#include <stdio.h> >> >>main(){ >> int fahr,celsius,lower,upper,step; >> lower=0; >> upper=300; >> step=20; >> fahr=lower; >> while (fahr<=upper) >> {celsius=5*(fahr-32)/9; >> printf("%d\t%d\n",fahr,celsuis; > > Did you notice the misspelling of celsius on the above line? No. My mistake then. ![]() > >> fahr=farh+step;}} >> >>/*end*/ |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
Bill Cunningham wrote:
> > I copied this code from page 9 k&r 2 and it gives an error that > even I can see. Celsius is uninialized. > > /* code */ > > #include <stdio.h> > > main(){ > int fahr,celsius,lower,upper,step; > lower=0; > upper=300; > step=20; > fahr=lower; > while (fahr<=upper) > {celsius=5*(fahr-32)/9; > printf("%d\t%d\n",fahr,celsuis; > fahr=farh+step;}} > > /*end*/ > > Celsius is intialized within the body of the while function. Why > is this code from k&r2 not working? Because that is not the code from K&R. -- Chuck F (cbfalconer at maineline dot net) <http://cbfalconer.home.att.net> Try the download section. -- Posted via a free Usenet account from http://www.teranews.com |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Bill Cunningham wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I > can see. Celsius is uninialized. > > /* code */ > > #include <stdio.h> > > main(){ > int fahr,celsius,lower,upper,step; > lower=0; > upper=300; > step=20; > fahr=lower; > while (fahr<=upper) > {celsius=5*(fahr-32)/9; > printf("%d\t%d\n",fahr,celsuis; > fahr=farh+step;}} > > /*end*/ > > Celsius is intialized within the body of the while function. Why is this > code from k&r2 not working? Most likely because of various typos which make it very different from the code in K&R2. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Bill Cunningham wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I > can see. Celsius is uninialized. > > /* code */ > > #include <stdio.h> > > main(){ > int fahr,celsius,lower,upper,step; > lower=0; > upper=300; > step=20; > fahr=lower; > while (fahr<=upper) > {celsius=5*(fahr-32)/9; > printf("%d\t%d\n",fahr,celsuis; > fahr=farh+step;}} > > /*end*/ > > Celsius is intialized within the body of the while function. Why is this > code from k&r2 not working? > > Bill > > Mine works.. #include <stdio.h> int main(void) { int fahr, celcius; int lower, upper, step; lower = 0; upper = 300; step = 20; fahr = lower; while (fahr <= upper) { celcius = 5 * (fahr - 32) / 9; printf("%d\t%d\n", fahr, celcius); fahr = fahr + step; } return 0; } -- Joe Wright "Everything should be made as simple as possible, but not simpler." --- Albert Einstein --- |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Bill Cunningham wrote:
>>> {celsius=5*(fahr-32)/9; >>> printf("%d\t%d\n",fahr,celsuis; >> >> Did you notice the misspelling of celsius on the above line? > > No. My mistake then. ![]() The Typo, the bane of compilation! I remember I once spent 2 hours trying to find the problem in a program (of mine) that failed to build, some times I wish they made a compiler that gave errors like: file:line !!! PEBKAC !!! sp,member != sp.member -- you are a blind idiot, After finally finding out that I had been working to long to notice the difference between , and . I decided to get a better font xD -- no brainer: A decision which, viewed through the retrospectoscope, is "obvious" to those who failed to make it originally. |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
Bill Cunningham wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I > can see. Celsius is uninialized. It has a value assigned before use, so what's the problem? [...] int fahr,celsius,lower,upper,step; [...] > while (fahr<=upper) > {celsius=5*(fahr-32)/9; [...] > Why is this > code from k&r2 not working? Is this really the code from K&R2? If it is, perhaps we should retreat to K&R1, where these lines are while )fahr <= upper) { celsius = (5.0/9.0) * (fahr-32.0); |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
"CBFalconer" <cbfalconer@yahoo.com> schrieb im Newsbeitrag
news:4749F6CE.B79E4735@yahoo.com... > Bill Cunningham wrote: >> >> I copied this code from page 9 k&r 2 and it gives an error that >> even I can see. Celsius is uninialized. >> >> /* code */ >> >> #include <stdio.h> >> >> main(){ >> int fahr,celsius,lower,upper,step; >> lower=0; >> upper=300; >> step=20; >> fahr=lower; >> while (fahr<=upper) >> {celsius=5*(fahr-32)/9; >> printf("%d\t%d\n",fahr,celsuis; >> fahr=farh+step;}} >> >> /*end*/ >> >> Celsius is intialized within the body of the while function. Why >> is this code from k&r2 not working? > > Because that is not the code from K&R. Very ful answer 8-( Fortunatly others had been far more full in pointing out the typo(s) Bye, Jojo |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
"Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag
news:5qv56aF11u6miU1@mid.individual.net... > Bill Cunningham wrote: >> I copied this code from page 9 k&r 2 and it gives an error that even >> I can see. Celsius is uninialized. > It has a value assigned before use, so what's the problem? > [...] > int fahr,celsius,lower,upper,step; > [...] >> while (fahr<=upper) >> {celsius=5*(fahr-32)/9; > [...] >> Why is this code from k&r2 not working? > > Is this really the code from K&R2? If it is, perhaps we should retreat to > K&R1, where these lines are > while )fahr <= upper) { > celsius = (5.0/9.0) * (fahr-32.0); Really? Does K&R1 have such bad typos? After correction it gives a warning: implicit conversion from "double" to "int": rounding, sign extension, or loss of accuracy may result Bye, Jojo |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
"Joe Wright" <joewwright@comcast.net> schrieb im Newsbeitrag
news:27SdnaWFpZvgp9fanZ2dnUVZ_hudnZ2d@comcast.com. .. > Bill Cunningham wrote: >> I copied this code from page 9 k&r 2 and it gives an error that even >> I can see. Celsius is uninialized. >> >> /* code */ >> >> #include <stdio.h> >> >> main(){ >> int fahr,celsius,lower,upper,step; >> lower=0; >> upper=300; >> step=20; >> fahr=lower; >> while (fahr<=upper) >> {celsius=5*(fahr-32)/9; >> printf("%d\t%d\n",fahr,celsuis; >> fahr=farh+step;}} >> >> /*end*/ >> >> Celsius is intialized within the body of the while function. Why is this >> code from k&r2 not working? >> >> Bill >> >> > Mine works.. > > #include <stdio.h> > > int main(void) > { > int fahr, celcius; > int lower, upper, step; > > lower = 0; > upper = 300; > step = 20; > > fahr = lower; > while (fahr <= upper) { > celcius = 5 * (fahr - 32) / 9; > printf("%d\t%d\n", fahr, celcius); > fahr = fahr + step; > } > return 0; > } Your code might work, but it too misspells celsius. Bye, Jojo PS: This is something I notice immediatelly, because Celsius(weg) is the street I live at... If I have to spell Celsius I usually refer to Fahrenheit, once with the result that it got spelled "Felsius" 8-) |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
Joachim Schmitz wrote:
> "Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag > news:5qv56aF11u6miU1@mid.individual.net... >> Bill Cunningham wrote: >>> I copied this code from page 9 k&r 2 and it gives an error that even >>> I can see. Celsius is uninialized. >> It has a value assigned before use, so what's the problem? >> [...] >> int fahr,celsius,lower,upper,step; >> [...] >>> while (fahr<=upper) >>> {celsius=5*(fahr-32)/9; >> [...] >>> Why is this code from k&r2 not working? >> Is this really the code from K&R2? If it is, perhaps we should retreat to >> K&R1, where these lines are >> while )fahr <= upper) { >> celsius = (5.0/9.0) * (fahr-32.0); > Really? Does K&R1 have such bad typos? No, that's my typo (and unless I missing something, that is properly singular). > > After correction it gives a warning: > implicit conversion from "double" to "int": rounding, sign extension, or > loss of accuracy may result While your implementation is free to issue such warnings, they are hardly required. People with a mania for compiles without warnings might take this is an indication that they should "fix" the code with a useless cast. Since casts to "shut the compiler up" are all too frequently a bad idea, I'm not so sure that the warning is a good idea. |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
In article <fidsvi$1gj$1@online.de>, Joachim Schmitz
<nospam.jojo@schmitz-digital.de> wrote on Monday 26 Nov 2007 1:05 pm: > "Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag > news:5qv56aF11u6miU1@mid.individual.net... >> Bill Cunningham wrote: >>> I copied this code from page 9 k&r 2 and it gives an error that >>> even >>> I can see. Celsius is uninialized. >> It has a value assigned before use, so what's the problem? >> [...] >> int fahr,celsius,lower,upper,step; >> [...] >>> while (fahr<=upper) >>> {celsius=5*(fahr-32)/9; >> [...] >>> Why is this code from k&r2 not working? >> >> Is this really the code from K&R2? If it is, perhaps we should >> retreat to K&R1, where these lines are >> while )fahr <= upper) { >> celsius = (5.0/9.0) * (fahr-32.0); > Really? Does K&R1 have such bad typos? > > After correction it gives a warning: > implicit conversion from "double" to "int": rounding, sign extension, > or loss of accuracy may result I could be wrong but, depending on the value in 'fahr', that statement might invoke undefined behaviour. |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
Joachim Schmitz said:
> "Joe Wright" <joewwright@comcast.net> schrieb im Newsbeitrag <snip> >> printf("%d\t%d\n", fahr, celcius); >> fahr = fahr + step; >> } >> return 0; >> } > Your code might work, but it too misspells celsius. > > Bye, Jojo > > PS: This is something I notice immediatelly, I note that your spelling flame contains a spelling error. It's heart-warming to see the old traditions being maintained. :-) -- Richard Heathfield <http://www.cpax.org.uk> Email: -http://www. +rjh@ Google users: <http://www.cpax.org.uk/prg/writings/googly.php> "Usenet is a strange place" - dmr 29 July 1999 |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
"Richard Heathfield" <rjh@see.sig.invalid> schrieb im Newsbeitrag
news:r5ednTvt4P9bCdfanZ2dnUVZ8vydnZ2d@bt.com... > Joachim Schmitz said: > >> "Joe Wright" <joewwright@comcast.net> schrieb im Newsbeitrag > > <snip> > >>> printf("%d\t%d\n", fahr, celcius); >>> fahr = fahr + step; >>> } >>> return 0; >>> } >> Your code might work, but it too misspells celsius. >> >> Bye, Jojo >> >> PS: This is something I notice immediatelly, > > I note that your spelling flame contains a spelling error. It's > heart-warming to see the old traditions being maintained. :-) After all I live at Celsiusweg, not at Immediately Drive 8-) Bye, Jojo |
|
|
|
#17 |
|
Messages: n/a
Hébergeur: |
"Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag
news:5qvg25F11d209U1@mid.individual.net... > Joachim Schmitz wrote: >> "Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag >> news:5qv56aF11u6miU1@mid.individual.net... >>> Bill Cunningham wrote: snip >> After correction it gives a warning: >> implicit conversion from "double" to "int": rounding, sign extension, or >> loss of accuracy may result > > While your implementation is free to issue such warnings, they are hardly > required. People with a mania for compiles without warnings might take > this is an indication that they should "fix" the code with a useless cast. > Since casts to "shut the compiler up" are all too frequently a bad idea, > I'm not so sure that the warning is a good idea. But in this case it tells me that using double arithmetic doesn't buy a thing in the first place. Bye, Jojo |
|
![]() |
| Outils de la discussion | |
|
|