While working on a project, I stumbled upon an issue. Some arithmetic using Preprocessor defined values resulted in 0.00
.
#include <stdio.h>
#define PINGCOUNT 10
int main()
{
int successful = 5;
int lossPercentage = ((PINGCOUNT - successful) / PINGCOUNT) * 100;
printf("%.2lf\n", lossPercentage);
return 0;
}
I re-ran this code in an online compiler and got the same result. I'm not sure if I am wording this poorly, but I'm having trouble finding information about this topic online.
The above code would work if I first declared int count = PINGCOUNT
, then replaced the PINGCOUNT
instances with count
. Additionally, I tried using PINGCOUNT
in some simple subtraction/addition and it worked properly. Is there something obvious that I'm missing?