www.digitalmars.com         C & C++   DMDScript  

c++.dos - long and double

reply TpW <TpW_member pathlink.com> writes:
What's wrong with my code?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main(void)
{
double  db;
long    lg;
lg = 316;
db = lg+1;
printf("lg=%d  db=%f\n",lg,db);
printf("db=%f\n",db);
}

dmc -ml test.cpp

When execute it show
lg=316  db=-23158417847463241000000000000000000000000000000000000000000000000000
0000000000.000000
db=317.000000
Jul 21 2004
parent Jan Knepper <jan smartsoft.us> writes:
TpW wrote:

 What's wrong with my code?
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
 void main(void)
 {
 double  db;
 long    lg;
 lg = 316;
 db = lg+1;
 printf("lg=%d  db=%f\n",lg,db);

try: printf ( "lg=%ld db=%f\n", lg, db );
 printf("db=%f\n",db);
 }
 
 dmc -ml test.cpp
 
 When execute it show
 lg=316  db=-23158417847463241000000000000000000000000000000000000000000000000000
 0000000000.000000
 db=317.000000
 
 

-- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org
Jul 21 2004