Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 23rd May 2004, 10:01 PM   (permalink)
Default Why the *********** isnt this simple C code working?

All this does is print the value of pi.
Why isnt this working. im using visual c++

#include <stdio.h>
#include <math.h>

void main()
{ float M_PI;

printf("M_PI = %.15f\n", M_PI);

}


M_PI is a constant defined as pi in the math.h library.
cubdh23 is offline  
Old 23rd May 2004, 10:33 PM   (permalink)
Default

visual c++ is made by microsoft and thus... it has bugs... :lol:

M_PI is not defined in microsofts math.h, so you'll need to define it yourself

#include <stdio.h>

#define M_PI 3.1415926535897932385

void main()
{

printf("M_PI = %.15f\n", M_PI);

}

also note that the line
float M_PI; is removed from your main function...
if something is defined (by you or in a header file) you shouldn't make a variable with the same name...
Exo is offline  
Old 23rd May 2004, 10:37 PM   (permalink)
Default

Thanks i tried it and it work.
cubdh23 is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 05:19 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker