| annmtui (2) | |
| #define pi=3.14 | |
|
Last edited on
|
|
| closed account (yUq2Nwbp) | |
|
#define MAX 8 ....where you write MAX compiler will understand it 8.. | |
|
|
|
| lnk2019 (200) | |
#define is a pre-processor directive, that replaces all occurrences of a specified identifier (in your case pi) with a value (which I assume for you is 3.14), it is not a variable definition in anyway.You need to remove the = sign from your #define pi=3.14 statement as the pre-processor will not understand it.The format of the #define directive is as follows:#define IDENTIFIER value , in your case it would be#define PI 3.14 , notice there is a space between PI and 3.14. Also there is a convention that identifiers for constants should be written in capitals.Here are some links that I hope will clear things up for you: http://www.cppreference.com/wiki/preprocessor/replace http://www.cplusplus.com/doc/tutorial/preprocessor/ I hope this helps! | |
|
|
|
| strongdrink (456) | |||
|
Try not to use #define too much though. in the above case.. if i were to write hi_PI, the processor would translate it to hi_3.14. so that could be a problem sometimes.. A better aproach would be using a namespace, like so. (outside of the main loop)
hope this helps and good luck! | |||
|
Last edited on
|
|||
| ascii (1022) | |||
Or just use a constant like:
| |||
|
Last edited on
|
|||
| bcthund (41) | |||
Another option if you are only using this in a specific area of your program is to use:
This can be pretty handy sometimes. | |||
|
|
|||
| ne555 (4383) | ||
Besides there is already M_PI in cmath | ||
|
|
||
| strongdrink (456) | |||
oh, didn't know that :D the previous post stated
| |||
|
|
|||