开发者

temperature converter not giving output

i have written a code for temperature conversion for iphone but it is not working and neither giving any error please help

interface section

#import <UIKit/UIKit.h>

float n ;
float k;



@interface farh_celcius_conv_AppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    UILabel *display;
    IBOutlet UITextField *farhenite;
    IBOutlet UIButton *convert;

}


-(IBAction) convert; 


@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UILabel *display;
@property (nonatomic, retain) IBOutlet UITextField *farheni开发者_如何学Gote;
@property (nonatomic, retain) IBOutlet UIButton *convert;
@end

implementation section

#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


If you want to convert the value entered in textField you the method should be like this

-(IBAction) convert  {

    NSString *str = yourTextField.text; // In your case farhenite i guess

    float n = [str floatValue];


      k = (n - 32)*(5/9);



    [display setText:[NSString stringWithFormat:@"%f",k]];  

}


if you wan to convert from textfield then it should be

NSString *str = textField.text;


Replace your function with below function. Than it will work fine.

-(IBAction) convert {

NSString *str = display.text;

float n = [str floatValue];


  k = (n - 32)*(5/9);



[display setText:[NSString stringWithFormat:@"%f",k]];  

}


If you Want to Convert the value from the farhenite text field,then it should be

-(IBAction) convert  {

    NSString *str = farhenite.text;

    float n = [str floatValue];


      k = (n - 32)*(5/9);



    [display setText:[NSString stringWithFormat:@"%f",k]];  

}


NSString *str = display.text;

Just replace the str declaration.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜