Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8227157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:01:35+00:00 2026-06-07T16:01:35+00:00

I have a program which runs fine, but I get no print output even

  • 0

I have a program which runs fine, but I get no print output even though I have a NSLog file in main.m Can you tell me what’s wrong? Thank you.

main.m

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

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

  @autoreleasepool {

    StockHolding *stockA;
    StockHolding *stockB;
    StockHolding *stockC;

    [stockA setPurchaseSharePrice:2.40];
    [stockA setCurrentSharePrice:3.12];
    [stockA setNumberOfShares:40];

    [stockB setPurchaseSharePrice:1.50];
    [stockB setCurrentSharePrice:1.41];
    [stockC setNumberOfShares:35];

    [stockC setPurchaseSharePrice:1.10];
    [stockC setCurrentSharePrice:1.20];
    [stockC setNumberOfShares:60];


    NSArray *holdings = [NSArray arrayWithObjects:stockA, stockB, stockC, nil];

    for (StockHolding *n in holdings) {
      // Call the methods
      float cost = [n costInDollars];
      float value = [n valueInDollars];
      NSLog(@"Bought stock for $%.2f, It is now at $%.2f, I have %d shares, They cost me $%.2f, Now they are worth $%.2f", [n purchaseSharePrice], [n currentSharePrice], [n numberOfShares], cost, value);
    }
  }
    return 0;
}

StockHolding.h

#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

StockHolding.m

#import "StockHolding.h"

@implementation StockHolding

@synthesize purchaseSharePrice, currentSharePrice, numberOfShares;

-(float)costInDollars
{
  return (purchaseSharePrice * numberOfShares);
}

-(float)valueInDollars
{
  return (currentSharePrice * numberOfShares);
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:01:39+00:00Added an answer on June 7, 2026 at 4:01 pm

    You haven’t actually created any of those StockHolding objects. Thus, your array is empty, and the loop doesn’t do anything.

    StockHolding *stockA;
    

    is just a declaration of a pointer. You need to create the object to which it points; the usual procedure is this:

    StockHolding *stockA = [[StockHolding alloc] init];
    

    Since, under ARC, object pointers are initialized to nil (which means “no object”), you are passing nil as all of the arguments to arrayWithObjects:. nil being the sentinel value meaning “there are no more arguments”, the array is created without contents.

    With an empty array, for (StockHolding *n in holdings) doesn’t have anything to enumerate over, so none of the code in the body of the loop, including your NSLog(), gets executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an RMI program which runs fine on my computer, but when I
I have a C program which compiles and runs fine under Linux without any
I have a program which runs an external, command line utility and reads the
I have a program which runs on a console and its Umlauts and other
So I have a program which runs. This is part of the code: FileName
I have a program which does a system call: latex somefile.latex This runs ok,
So I have a Linux program that runs in a while(true) loop, which waits
I have a python script that runs a program, which generates few .exe files
I have a class called ModelView which inherits from NSOpenGLView. When my program runs
I have a django project which runs just fine with runserver located in: D:\EverTabs\work\evertabs-website\src\evertabs\

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.