Click to See Complete Forum and Search --> : Float display as 0


mbanghart
August 1st, 2008, 10:50 AM
Hi,

The following only outputs a zero. Not sure why.

cout << "Percent Connected: " << (Ccounter/(totalElements*6))*100 << " %\n\n" << endl;

Ccounter and totalElements are Ints.

Thanks

GNiewerth
August 1st, 2008, 11:03 AM
Integer arithmetics rounds everything down to the next smaller int. Try to convert your operands to double before dividing.

0xC0000005
August 1st, 2008, 11:23 AM
Casting one of the ints should do it, then all other ints will be promoted in the calculation.

cout << "Percent Connected: " << ((double)Ccounter/(totalElements*6))*100 << " %\n\n" << endl;