Verification of input from key

59 views Asked by At

I apologize for my bad English.

How could you do "textFiled1.text" check is less than 10 multiplied by 5, if more than 10 multiplied by 20

  -(IBAction)calculate
{
float x = ([textFiled1.text floatValue]);

float c = x*10;

lable.text = [[NSString alloc] initWithFormat:@"%2.f", c]; 

}
2

There are 2 answers

0
sch On
-(IBAction)calculate
{
    float x = [textFiled1.text floatValue];

    float c = 0;

    if (x <= 10) { // Or < instead of <=
        c = x * 5;
    else {
        c = x * 20;
    }

    lable.text = [[NSString alloc] initWithFormat:@"%2.f", c]; 
}

Or in one line:

float c = (x <= 10) ? x * 5 : x * 20; // Or < instead of <=
0
esqew On
float c;

if (x < 10) {
    c = x*10;
} else if (x >10) {
    c = x*20;
}