|
-
August 1st, 2008, 10:50 AM
#1
Float display as 0
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
-
August 1st, 2008, 11:03 AM
#2
Re: Float display as 0
Integer arithmetics rounds everything down to the next smaller int. Try to convert your operands to double before dividing.
- Guido
-
August 1st, 2008, 11:23 AM
#3
Re: Float display as 0
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;
Last edited by 0xC0000005; August 1st, 2008 at 11:24 AM.
Reason: remove quoted text
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|