All of the values below are doubles, yet switch requires a integer value. Is there anyway around this?
switch(fivePercentValue){
case floor((5*fivePercentValue) / 100):
fivePercent_.backgroundColor = [UIColor greenColor];
fivePercentLabel_.textColor = [UIColor greenColor];
break;
case ceil((5*fivePercentValue) / 100):
fivePercent_.backgroundColor = [UIColor greenColor];
fivePercentLabel_.textColor = [UIColor greenColor];
break;
default:
fivePercent_.backgroundColor = [UIColor redColor];
fivePercentLabel_.textColor = [UIColor redColor];
break;
You are probable better of just using if else and testing for ranges but you can perform some maths on your fivePercentValue
and then convert it to an integer so that different integers represent different ranges for example
switch( (int)(value*10.0) )
{
case 0: // this is 0.0 <= value < 0.1
break;
case 1: // this is 0.1 <= value < 0.2
break;
case 2: // this is 0.2 <= value < 0.3
break;
....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With