The code is supposed to be a basic objc program that contains a list of purchased stocks, foreign and domestic. Right now, I have to put them into a portfolio and sum it up. I realized that I could not sum them up because I was getting an error with my BNRForeign header and implementation files. For the rest of the code, please see here (my other question that was answered): Trying to create a portfolio of stocks with a total value in Objective-C, but unsure of the approach
So I'm working on some code for a stock problem from a book that I'm reading, which was partly answered in another question I posted yesterday. I have an entirely new question branching from that now.
For my if condition, I want to iterate through an array, but I'm not sure how to implement this.
My main.m:
int main(int argc, const char * argv[]) {
@autoreleasepool {
BNRStockHolding *stock0 = [[BNRStockHolding alloc]init];
BNRStockHolding *stock1 = [[BNRStockHolding alloc]init];
BNRStockHolding *stock2 = [[BNRStockHolding alloc]init];
BNRForeignStockHolding *stock3 = [[BNRForeignStockHolding alloc]init];
stock0.purchaseSharePrice=2.30;
stock0.currentSharePrice=4.50;
stock0.numberOfShares=40;
stock1.purchaseSharePrice=12.19;
stock1.currentSharePrice=10.56;
stock1.numberOfShares=90;
stock2.purchaseSharePrice=45.10;
stock2.currentSharePrice=49.51;
stock2.numberOfShares=210;
stock3.purchaseSharePrice=43.05;
stock3.currentSharePrice=28.31;
stock3.numberOfShares=15;
NSMutableArray *stocks = [NSMutableArray arrayWithObjects:stock0, stock1, stock2, stock3, nil];
for (BNRForeignStockHolding *s in stocks) {
float a = s.purchaseSharePrice;
float b = s.currentSharePrice;
int c = s.numberOfShares;
float d = s.costInDollars;
float e = s.valueInDollars;
float f = s.foreignCostInDollars;
float g = s.foreignValueInDollars;
if () {
NSLog(@"\n Purchase Price: %.2f\n Current Price: %.2f\n Number of Shares %d\n Cost in Dollars %f\n Value in Dollars %f\n", a, b, c, d, e);
}
else {
NSLog(@"\n Purchase Price: %.2f\n Current Price: %.2f\n Number of Shares %d\n Cost in Dollars %f\n Value in Dollars %f\n", a, b, c, f, g);
}
}
}
return 0;
}
Basically, for stock0, stock1, and stock2, I need NSLog to apply functions a, b, c, d, e. For stock3, I need NSLog to apply functions a, b ,c, f, g.
I tried things like this:
if (stock(i), i=0, i<=2) {
NSLog(@"etc", a, b, c, d, e);
}
else {
NSLog(@"etc", a, b, c, f, g);
}
Xcode keeps stating that stock(i) and i are undefined implicit functions and that they are undeclared. I understand this, but since I am new to programming, I am unsure of how to define them so that I may iterate through my array.
Thanks for your help!