开发者

Check for blocking a string in iPhone

开发者 https://www.devze.com 2023-03-05 02:34 出处:网络
I have made a Fahrenheit to Celcius converter. I want to block a string so that it is not taken by iPhone as input.

I have made a Fahrenheit to Celcius converter. I want to block a string so that it is not taken by iPhone as input.

#import "farh_celcius_conv_AppDelegate.h"

@implementation farh_celcius_conv_AppDelegate
@synthesize window,display,farhenite;

-(IBAction) convert {
    NSString *str 开发者_运维问答= [NSString text];
    float n = [str floatValue];
    k = (n - 32)*(5/9);
    [display setText:[NSString stringWithFormat:@"%f",k]];  
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

- (void)dealloc {
    [window release];
    [super dealloc];
}

@end


Ok, after parsing the question, here's another answer.

Replace:

k = (n - 32)*(5/9);
[display setText:[NSString stringWithFormat:@"%f",k]];  

With:

if (n != 0) {
  k = (n - 32)*(5/9);
  [display setText:[NSString stringWithFormat:@"%f",k]];  
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号