|
From: Ioannis V. <iv...@em...> - 2003-03-20 17:15:42
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of francesca=20
> Sent: Thursday, March 20, 2003 5:28 PM
> To: dev...@li...
> Subject: [Dev-C++] help float
>=20
>=20
> Hi,
> I use Dev-C++ 9.7.0 OS Win 2000.
> When I write simply:
>=20
> #include <iostream>=20
// stdio.h is not needed
> #include <stdio.h>=20
> #include <stdlib.h>=20
Better: #include <cstdlib>
Better not using-statement here.
> using namespace std;
>=20
>
> main()
Int main()
> {
using namespace std;
> float a;
> a=3D16/3;
> cout<<a<<endl;
> system("PAUSE");
> return 0;
> }
>=20
> the compilation finishes correctly, but the program=20
> visualizes only 5 without decimates them!=20
> why?
16/3 is an int expression. The result is then converted and assigned to =
your
float. 16.0/3 (which is double), or 16.0f/3 would do the job you want.
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
|