Problem finishing Challenge 19


#1

So my program builds fine and then when it runs i get "GD8L Program received signal: “SIGABRT” and i get warning in my main.m file for the methods I used from Portfolio. I’ve been messing with it for a long time and finally decided to post this… Can someone help me out here? what am I doing wrong? Thanks for the help!

main.m

[code]//
// main.m
// Stocks
//
// Created by Britton Miller on 6/21/13.
// Copyright 2013 MyCompanyName. All rights reserved.
//

#import <Foundation/Foundation.h>
#import “Portfolio.h”
#import “ForeignStockHolding.h”

int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

StockHolding *stock1 = [[StockHolding alloc] init];
ForeignStockHolding *stock2 = [[ForeignStockHolding alloc] init];
StockHolding *stock3 = [[StockHolding alloc] init];

[stock1 setNumberofShares:5];
[stock1 setCurrentSharePrice:5.5];
[stock1 setPurchaseSharePrice:4.3];

[stock2 setNumberofShares:5];
[stock2 setCurrentSharePrice:5.5];
[stock2 setPurchaseSharePrice:4.3];
[stock2 setConversionRate:2.0];

[stock3 setNumberofShares:5];
[stock3 setCurrentSharePrice:5.5];
[stock3 setPurchaseSharePrice:4.3];


[Portfolio addToDomesticStock:stock1];
[Portfolio addToForeignStock:stock2];
[Portfolio addToDomesticStock:stock3];

//for(StockHolding *d in Stocks)
//{
//    NSLog(@" %d Shares cost %.2f and are now worth %.2f",[d numberofShares],[d costInDollars],[d valueInDollars]);
//}

NSLog(@"The entire portfolio is worth %@.", [Portfolio portfolioValue]);

[pool drain];
return 0;

}[/code]

Portfolio.h

#import <Foundation/Foundation.h>
#import "ForeignStockHolding.h"

@interface Portfolio : NSObject 
{
	NSMutableArray *domesticStocks;
	NSMutableArray *foreignStocks;
}
- (float)portfolioValue;
- (void)addToDomesticStocks:(StockHolding *)domestic;
- (void)addToForeignStocks:(ForeignStockHolding *)foreign;

@end

Portfolio.m

[code]//
// Portfolio.m
// Stocks
//
// Created by Britton Miller on 6/24/13.
// Copyright 2013 MyCompanyName. All rights reserved.
//
#import<Foundation/Foundation.h>
#import “Portfolio.h”
#import “ForeignStockHolding.h”

@implementation Portfolio

  • (void)addToDomesticStocks:(StockHolding *)domestic
    {
    if(!domesticStocks)
    domesticStocks = [[NSMutableArray alloc] init];
    NSLog(@“here”);
    [domesticStocks addObject];
    }

  • (void)addToForeignStocks:(ForeignStockHolding *)foreign
    {
    if(!foreignStocks)
    foreignStocks = [[NSMutableArray alloc] init];
    [foreignStocks addObject:foreign];
    }

-(float)portfolioValue{
float fsum = 0;
float dsum = 0;
for (ForeignStockHolding *s in foreignStocks)
fsum += [s valueInDollars];
for (StockHolding *d in domesticStocks)
dsum += [d valueInDollars];
return dsum+fsum;
}

@end
[/code]

ForeignStockHolding.h

[code]//
// ForeignStockHolding.h
// Stocks
//
// Created by Britton Miller on 6/23/13.
// Copyright 2013 MyCompanyName. All rights reserved.
//

#import <Foundation/Foundation.h>
#import “StockHolding.h”

@interface ForeignStockHolding : StockHolding
{
float conversionRate;
}
@property float conversionRate;

@end
[/code]

ForeignStockHolding.m

[code]//
// ForeignStockHolding.m
// Stocks
//
// Created by Britton Miller on 6/23/13.
// Copyright 2013 MyCompanyName. All rights reserved.
//

#import “ForeignStockHolding.h”

@implementation ForeignStockHolding

@synthesize conversionRate;

  • (float)costInDollars
    {
    return [super purchaseSharePrice][self conversionRate][super numberofShares];
    }
  • (float)valueInDollars
    {
    return [super currentSharePrice][self conversionRate][super numberofShares];
    }

@end
[/code]

StockHolding.h

[code]//
// StockHolding.h
// Stocks
//
// Created by Britton Miller on 6/21/13.
// Copyright 2013 MyCompanyName. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface StockHolding : NSObject
{
float purchaseSharePrice;
float currentSharePrice;
int numberOfShares;
}
@property float purchaseSharePrice;
@property float currentSharePrice;
@property int numberofShares;

  • (float)costInDollars;
  • (float)valueInDollars;

@end
[/code]

StockHolding.h

[code]//
// StockHolding.h
// Stocks
//
// Created by Britton Miller on 6/21/13.
// Copyright 2013 MyCompanyName. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface StockHolding : NSObject
{
float purchaseSharePrice;
float currentSharePrice;
int numberOfShares;
}
@property float purchaseSharePrice;
@property float currentSharePrice;
@property int numberofShares;

  • (float)costInDollars;
  • (float)valueInDollars;

@end
[/code]


#2

Problem in main ():

I let you zoom in on it. Ask your self what kind of value %@ expects, and what kind of value [Portfolio portfolioValue] returns.

Fix this problem first.


#3

[quote=“ibex10”]Problem in main ():

I let you zoom in on it. Ask your self what kind of value %@ expects, and what kind of value [Portfolio portfolioValue] returns.

Fix this problem first.[/quote]

Thanks for catching that. I changed it to return a float. I still have the same problem though.