i am new to programming and i need your help…
i have a label named “typeLabel” that has a default label text se to “NiMH”. This text changes to NiCad through a pickerView. I want through an if-statement to change a multiplier value however “unused variable floatTime” halts the program. The code is:
-(IBAction)calculate:(id)sender {
if ([typeLabel.text isEqualToString:@"NiCad"])
{
float floatTime=([mAhLabel.text floatValue]/chargerSlider.value)*1.4;
} else {
float floatTime=([mAhLabel.text floatValue]/chargerSlider.value)*1.5;
}
int intHourhs=(floatTime);
float floatHours=(intHourhs);
float floatMinutes=(floatTime-floatHours)*60;
NSString *stringTotal = [NSString stringWithFormat: @"%1.1i Hours and %.0f Minutes", intHourhs, floatMinutes];
chargeLabel.text=stringTotal;
}
You need to move the declaration above the if statement:
When you declare a local variable inside a scope it is not visible outside that scope.