A few notes:
- IIRC, integer vs float division is decided by the operands, not the target. Meaning that
Code:
int i = 5.0 / 3.0 * 4.0
will be 6, while
Code:
float i = 5 / 3 * 4
will be 4. - For counters and times, and any other values that don't go negative, you should be declaring them as "unsigned". That is, "unsigned int", "unsigned long", etc. This doubles the upper bound and causes it to wrap to 0, not a negative number.
- remember the data types: char = 1B, int = 2B, short long = 3B, long = 4B
- Any time you think a calculation will over flow, cast one of the operands to a long. "((i * 262L) / 10000L)" should work fine for you.
Also, I find a series of typedef's helpful:
Code:
typedef signed char SCHAR;
typedef unsigned char UCHAR;
typedef signed int SINT;
typedef unsigned int UINT;
typedef signed short long SSHORT;
typedef unsigned short long USHORT;
typedef signed long SLONG;
typedef unsigned long ULONG;
Put that in a "types.h", and include it basically everywhere. A good place to define a "bool" type as well.