Currency Converter Bug

Discussion in 'Mac Programming' started by satans_banjo, Nov 5, 2005.

  1. macrumors regular

    Joined:
    Sep 12, 2005
    Location:
    SE London
    #1
    i've followed the cocoa currency converter tutorial from the apple web site and i've managed to build it fine, but when i run it i get strange results for my currency conversions. i was wondering if you would be able to recognise what the problem is

    here is the code i put into the files:

    ConverterController.m
    Code:
    #import "ConverterController.h"
    #import "Converter.h"
    
    @implementation ConverterController
    - (IBAction)convert:(id)sender
    {
    	float rate, currency, amount;
    	currency = [dollarField floatValue];
    	amount = [converter convertCurrency:currency atRate:rate];
    	[amountField setFloatValue:amount];
    	[rateField selectText:self];
    }
    
    @end
    ConverterController.h:
    Code:
    /* ConverterController */
    
    #import <Cocoa/Cocoa.h>
    
    @interface ConverterController : NSObject
    {
        IBOutlet NSTextField *amountField;
        IBOutlet id converter;
        IBOutlet NSTextField *dollarField;
        IBOutlet NSTextField *rateField;
    }
    - (IBAction)convert:(id)sender;
    @end
    
    Converter.m:
    Code:
    #import "Converter.h"
    
    @implementation Converter
    -	(float)convertCurrency:(float)currency atRate:(float)rate	{
    		return currency * rate;
    }
    @end
    Converter.h:
    Code:
    /* Converter */
    
    #import <Cocoa/Cocoa.h>
    
    @interface Converter : NSObject {}
    - (float)convertCurrency:(float)currency atRate:(float)rate;
    @end
    
    i didn't get any build errors or warnings for any of these. i've also taken some screenshots of what i did in interface builder to see if there was a problem there
     

    Attached Files:

  2. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #2
    Your ConverterController.h file is the same as the .m file. Is that what you meant to post? If so, it's wrong. The .h is for variable and method declarations - not code.

    BTW, you've got an icon on your dock that looks like a dog with chopsticks. What app is that?
     
  3. thread starter macrumors regular

    Joined:
    Sep 12, 2005
    Location:
    SE London
    #3
    it's doggibox - a drum sequencing app. it's a good app and it's shareware so there's no obligation to buy anything

    thanks for pointing that out. i must have been not paying attention and just copied the same code into both files

    EDIT: actually hang on, i copied the .m twice. i've edited it now
     
  4. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #4
    The reason it's not working is that you're missing a line in ConverterController.m that says

    rate=[rateField floatValue];

    otherwise rate just has any old random value in it.

    BTW, you should really pay for shareware you use (says the shareware developer ;) )
     
  5. thread starter macrumors regular

    Joined:
    Sep 12, 2005
    Location:
    SE London
    #5
    wahey! thanks!

    oh yeah - the shareware price is to unlock new features, which i don't need right now. of course it's a great program so if i ever get around to making a profit on my home recordings it'll be th first thing i invest in
     

Share This Page