home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!nuscc!eletanjm
- From: eletanjm@nuscc.nus.sg (TAN JIN MENG)
- Subject: Re: Help!!! Please Read this message!?!?!?!?!...
- Message-ID: <1992Sep9.042539.13326@nuscc.nus.sg>
- Organization: National University of Singapore
- References: <1992Sep9.041243.11893@nuscc.nus.sg>
- Date: Wed, 9 Sep 1992 04:25:39 GMT
- Lines: 65
-
- eletanjm@nuscc.nus.sg (TAN JIN MENG) writes:
- : eletanjm@nuscc.nus.sg (TAN JIN MENG) writes:
- : : gmr6139@ultb.isc.rit.edu (G.M. Richard ) writes:
- : : : I can't get my compiler to do float-type variables. I can do
- : : : integers, and I can declare integers, but I can't either
- : : : declare a real number or define a float variable. This is no
- : : : little typo here - the same programs work when compiled on a
- : : : VAX, but when I compile this program with Turbo C, all I get
- : : : is zeroes for floats. Take a look:
- : : :
- : : : /* Variable Example */
- : : :
- : : : #include <stdio.h>
- : : :
- : : : #define apples 4
- : : : #define oranges 3.6
- : : :
- : : : main()
- : : : {
- : : : printf("\nApples = %d\nOranges = %f", apples, oranges);
- : : : }
- : : :
- : : :
- : : : output:
- : : :
- : : : Apples=4
- : : : Oranges=0.000000
- : :
- : : Your compiler can't know what orange is... So it assumes that its an
- : : int. That's why the wrong result. Alternatives ...
- : :
- : : 1) printf("\nApples = %d\nOranges = %f",(int)apples, (float)oranges);
- : :
- : : 2) declare
- : : const float oranges = 3.6;
- :
- : Sorry, my explanation is obviously misleading. The examples should work
- : however.
-
- Sigh.... Before someone writes to me flaming me, I'd better explain. I've
- encountered a similar problem before (can't remember with which
- compiler though) and what happened was that the compiler was pushing
- ints as arguments.
-
- BTW has anyone ever encountered a compiler (used intensively) that
- didn't have a bug of some kind or other?
- :
- : :
- : : :
- : : :
- : : : Any help on this problem would be greatly appreciated!!!!
- : : :
- : : :
- : : : --
- : : : _ _ __ gmr6139@ultb.isc.rit.edu
- : : : /| /| __ _/__/_ /__) ' __ /_ __ ,_ __/ gmr6139@george.cs.rit.edu
- : : : / |/ |_/-/__/__/____/ \__/_/___/ /_/-/_/__/_/ gmr6139@ritvax.isc.rit.edu
- : : : ____________________________________________ gmr6139@ritlav.isc.rit.edu
- : :
- : : jin meng
- :
- : jin meng
-
-
- jin meng
-