View Full Version : Currency Converter Bug

Nov 5, 2005, 06:25 AM
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:

#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];


/* ConverterController */

#import <Cocoa/Cocoa.h>

@interface ConverterController : NSObject
IBOutlet NSTextField *amountField;
IBOutlet id converter;
IBOutlet NSTextField *dollarField;
IBOutlet NSTextField *rateField;
- (IBAction)convert:(id)sender;

#import "Converter.h"

@implementation Converter
- (float)convertCurrency:(float)currency atRate:(float)rate {
return currency * rate;

/* Converter */

#import <Cocoa/Cocoa.h>

@interface Converter : NSObject {}
- (float)convertCurrency:(float)currency atRate:(float)rate;

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

Nov 5, 2005, 03:31 PM
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?

Nov 5, 2005, 05:15 PM
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

Nov 6, 2005, 03:25 AM
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 ;) )

Nov 6, 2005, 04:34 AM
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