Jump to content


C Question


3 replies to this topic

#1 ♥i-love-you♥

    I love my little ray of sunshine

  • MOD
  • 11,831 posts
  • Gender:Male
  • Location:under your bed, Scotland

Posted 16 August 2010 - 09:12 PM

Ok, so I'm learning C and I made this:

ftoc2()
{
	printf("   F	  C\n");
	int fahr;
	for(fahr = -100; fahr <= 100; fahr+=20){
		printf("%4.0d %6.1f\n", fahr, (5.0/9.0)*(fahr-32.0));
	}
}

Which works fine, apart from when fahr = 0, then it just outputs nothing:

   F	  C
-100  -73.3
 -80  -62.2
 -60  -51.1
 -40  -40.0
 -20  -28.9
	  -17.8
  20   -6.7
  40	4.4
  60   15.6
  80   26.7
 100   37.8

Anyone know why?

#2 ♥i-love-you♥

    I love my little ray of sunshine

  • MOD
  • 11,831 posts
  • Gender:Male
  • Location:under your bed, Scotland

Posted 16 August 2010 - 09:43 PM

Not lazy enough how?

Starting at -101 it correctly outputs -1 in that position. Maybe it just doesn't display it because it's empty?

#3 ♥i-love-you♥

    I love my little ray of sunshine

  • MOD
  • 11,831 posts
  • Gender:Male
  • Location:under your bed, Scotland

Posted 16 August 2010 - 10:28 PM

Oh right, I missed that first time round somehow.

Hmm. Oh well, I shall move onto the next thing and try to figure it out when I know a bit more. Could do with a better book though.

#4 SaffronJava

    Geeky Sheep-Shagger

  • Members
  • PipPipPipPipPipPipPipPipPipPip
  • 6,004 posts
  • Gender:Male
  • Location:Glasgow, United Kingdom

Posted 21 August 2010 - 01:06 PM

View Post♥i-love-you♥, on Aug 16 2010, 11:28 PM, said:

Oh right, I missed that first time round somehow.

Hmm. Oh well, I shall move onto the next thing and try to figure it out when I know a bit more. Could do with a better book though.
What book are you using?

Change:
printf("%4.0d %6.1f\n", fahr, (5.0/9.0)*(fahr-32.0));

to:
printf("%d, %.1f \n", fahr, (5.0/9.0)*(fahr-32.0));





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users