I'm having trouble passing a float value from one object to another. It appears to be fine in the first method, but in the second its value is huge. I assume this is some kind of a problem with my typecasting, because that's the thing I understand the poorest. Help is greatly appreciated!
In my game controller, I do this:
float accuracy = (float)hitCount/(float)(hitCount+missCount);
NSLog(@"GameController - hits: %i misses: %i enemies: %i accuracy: %f", hitCount, missCount, escapedCount, accuracy);
[delegate postGameWithScore:roundScore andAccuracy:accuracy];
Which invokes this method in the game controller's delegate:
-(void)postGameWithScore:(NSInteger)score andAccuracy:(float)accuracy {
cumulativeScore += score;
NSLog(@"GameMaster - score: %i accuracy %f",cumulativeScore, accuracy);
/* non relevant code clipped */
}
Output:
GameController - hits: 14 misses: 54 enemies: 35 accuracy: 0.205882
GameMaster - score: 3800 accuracy 36893488147419103232.000000
I can't figure out why accuracy
is not correct in the second NSLog.