I'm getting an error from Xcode 4.2.1 'Sending 'double' to parameter of incompatible type 'NSNumber'.
Please help.
the error occurs at the following (which can be found in position below)
The code goes like this...
Please help.
the error occurs at the following (which can be found in position below)
for (NSNumber *aTransaction in europeTransactions) {
[europeBudget spendDollars: [aTransaction doubleValue]];
}
[europeBudget spendDollars: [aTransaction doubleValue]];
}
The code goes like this...
Code:
#import <Foundation/Foundation.h>
@interface
Budget : NSObject
{
float exchangeRate;
double budget;
double exchangeTransaction;
}
- (void) createBudget: (double) aBudget withExchangeRate: (float) anExchangeRate;
- (void) spendDollars: (NSNumber*) dollars;
- (void) chargeForeignCurrency: (double) foreignCurrency;
@end
@implementation
Budget
- (void) createBudget: (double) aBudget withExchangeRate: (float) anExchangeRate {
budget = aBudget;
exchangeRate = anExchangeRate;
}
- (void) spendDollars: (NSNumber*) dollars {
budget -= [dollars doubleValue];
NSLog(@"Converting %.2f US dollars into foreign currency leaves $%.2f", [dollars doubleValue], budget);
}
- (void) chargeForeignCurrency: (double) foreignCurrency {
exchangeTransaction = foreignCurrency*exchangeRate;
budget -= exchangeTransaction;
NSLog(@"Charging %.2f in foreign currency leaves $%.2f", foreignCurrency, budget);
}
@end
int main (int argc, const char * argv[]) {
double numberEuros = 100;
NSNumber *europeDollarTransaction = [[NSNumber alloc] initWithDouble:100];
NSNumber *europeDollarTransaction2 = [[NSNumber alloc] initWithDouble:200];
NSMutableArray *europeTransactions = [[NSMutableArray alloc] initWithCapacity:1];
[europeTransactions addObject:europeDollarTransaction];
[europeTransactions addObject:europeDollarTransaction2];
Budget *europeBudget = [Budget new];
[europeBudget createBudget:1000.00 withExchangeRate:1.2500];
for (NSNumber *aTransaction in europeTransactions) {
[europeBudget spendDollars: [aTransaction doubleValue]];
}
[europeBudget chargeForeignCurrency:numberEuros];
return 0;
}
Last edited by a moderator: