控制台输出错误

问题描述:

正在运行这段代码,但输出错误。应该得到:控制台输出错误

Converting 100.00 US dollars into foreign currency leaves $900.00 
Charging 100.00 in foreign currency leaves $775.00 Converting 100.00 US dollars into foreign currency leaves 
$1900.00 
Charging 100.00 in foreign currency leaves $1750.00 

,但我只得到:

Converting 100.00 US dollars into foreign currency leaves $900.00 

下面是代码:

#import <Foundation/Foundation.h> 

@interface Budget:NSObject { 
    float exchangeRate; 
    double budget; 
    double exchangeTransaction; 
} 

- (void) createBudget:(double)aBudget withExchangeRate:(float) anExchangeRate; 

- (void) spendDollars:(double)dollars; 

- (void) chargeForeignCurrency:(double)foreignCurrency; 

@end 

@implementation Budget 

- (void) createBudget:(double)aBudget withExchangeRate:(float) anExchangeRate { 
    exchangeRate = anExchangeRate; 
    budget = aBudget; 
} 

- (void) spendDollars:(double)dollars { 
    budget -= dollars; 
    NSLog(@"Converting %.2f US dollars into foreign currency leaves $%.2f", dollars, 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 numberDollarsInEuroland = 100; 
    double numberEuros = 100; 
    double numberDollarsInPoundland = 100; 
    double numberPounds = 100; 

    Budget *europeBudget = [Budget new]; 
    [europeBudget createBudget:1000.00 withExchangeRate:1.2500]; 
    [europeBudget spendDollars:numberDollarsInEuroland]; 
    [europeBudget chargeForeignCurrency:numberEuros]; 

    Budget *englandBudget = [Budget new]; 
    [englandBudget createBudget:2000.00 withExchangeRate:1.5000]; 
    [englandBudget spendDollars:numberDollarsInPoundland]; 
    [englandBudget chargeForeignCurrency:numberPounds]; 



    return 0; 
} 

有什么不对?提前致谢。

+0

我没有看到任何错误。我编译并运行它,得到了你期望的结果。 – 2012-04-14 17:50:39

+0

这是我的输出:将100.00美元转换成外币叶子900.00美元 收取外币叶子100.00美元775.00 将100.00美元转换成外币叶子1900.00美元 收取100.00美元的外币叶子$ 1750.00 – 2012-04-14 17:52:02

+0

很奇怪。我试过你的代码,并且一切正常。输出我有你想要的。 – RomanHouse 2012-04-14 18:37:24

只是一个猜测,但是这是在命令行工具中的代码?如果是这样,请检查this is your problem