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 7049029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:57:47+00:00 2026-05-28T02:57:47+00:00

I’m new to programming, I have some basic python programming from college, I am

  • 0

I’m new to programming, I have some basic python programming from college, I am familiar with some of the OOP basics and would like some help with managing large amounts of integers. I have 88 of them. 7 will be used for capturing user input and the other 81 will be used for a specific calculation. Instead of writing the following code:

int currentPlace;
int futurePlace;
int speed;
int distance;

int place1 = 1;
int place2 = 2;
int place3 = 3;
// etc...
int place81 = 81;

And then later coming back to the integers and asking user defined questions such as:

NSLog(@"What place is the runner in?");
scanf("%i", &currentPlace);
NSLog(@"What place does the runner finish in?");
scanf("%i", &futurePlace);
NSLog(@"What is the distance of the track?");

// doing some math

NSLog(@"The runner is running at "i" MPH.",speed);

I remember there being an easier way to use the integers but I keep thinking enums or typedefs.

I’d like for the user to pick a number and not have to run a huge if statement to get the work done to cut the size of the program as much as possible.

This is my first “on my own” application so any helpful pointers would be great.

Thanks.

  • 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-05-28T02:57:48+00:00Added an answer on May 28, 2026 at 2:57 am

    I haven’t understood why you need all these place‘s, but I also assume that an array would be easier to use here. You can use either NSArray or NSMutableArray. The difference between them is that an NSArray instance can’t be changed after being created (you can’t add/remove elements) unlike an NSMutableArray.

    Using NSArray

    NSArray *places = [NSArray arrayWithObjects:[NSNumber numberWithInt:1], [NSNumber numberWithInt:2],[NSNumber numberWithInt:3], ..., [NSNumber numberWithInt:81],  nil];
    

    nil at the end means the end of the contents of an array. [NSNumber numberWithInt:1] returns an int given as an argument (we can’t straight give an int to the array, as an array expects an object as an argument.

    You can access the contents of the array using:

    [places objectAtIndex:(NSUInteger)];
    

    Remeber that an array starts counting with 0, so if you want to get 5, you have to do this

    [places objectAtIndex:4];
    

    Using NSMutableArray

    I suggest that you should use this option.

    It’s easier to use for here.

    NSMutableArray *places = [NSMutableArray array];
    for (int i = 1; i < 81; i++)
    {
        [places addObject:[NSNumber numberWithInt:i]];
    }
    

    Then you can access data the same way as in the NSArray:

    [places objectAtIndex:0];
    

    This will return 1. You can start the for-cycle with 0. After that the index of an array will correspond to the integer inside, so

    [places objectAtIndex:5];
    

    will actually return 5.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a text area in my form which accepts all possible characters from
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.