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]];
}
精彩评论