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

  • Home
  • SEARCH
  • 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 8154139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:14:29+00:00 2026-06-06T16:14:29+00:00

I am reading Programming in Objective-C 4th Ed. by Stephen G. Kochan. In the

  • 0

I am reading “Programming in Objective-C” 4th Ed. by Stephen G. Kochan. In the book, there is a sample code for creating a Calculator application for the iPhone. I understand the code, at least 90% of it. – There is a Fraction class that has methods to store fraction objects and that describe how to perform different basic fraction arithmetic operations
– In addition to that, there is a calculator class that runs the appropriate methods from the Fraction class depending on whether the user is trying to sum, divide etc.

The view controller has the following method for when the user presses a number in the interface:

-(IBAction)clickDigit:(UIButton *)sender {
int digit = sender.tag;     //sender or the argument inthis case is  the button

[self processDigit:digit];
}

As you see this method is now called:

-(void) processDigit:(int)digit {
currentNumber = currentNumber * 10 + digit;

[displayString appendString:
 [NSString stringWithFormat:@"%i", digit]];
display.text = displayString;

}

My ONLY question (and probably the one with the most simple answer) is: Why is currentNumber always multiplied by 10? The value of currentNumber is always 0 by the time the compiler enters the method above (I verified this using the debugger in XCode) so i dont get why we even have to multiply it by 10. I did delete that multiplication and the results are incorrect, i just cannot figure out why yet.

Thank you

  • 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-06T16:14:32+00:00Added an answer on June 6, 2026 at 4:14 pm

    Maybe the best way to think about this is with an example.

    Imagine the user has clicked the following digits in order: 1, 2. Then, assuming the code is working, the numeric value of currentNumber should be 12.

    Now imagine the user next clicks on ‘3’. Now you want the value to be 123. You can get this by multiplying the previous value (12) by 10 and then adding the 3. If they then click on a ‘4’, the value should become 1,234, which is achieved by 10 * 123 + 4. And so on.

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

Sidebar

Related Questions

Hi, guys! Currently I'm reading a book Programming in Objective-C by Stephen Kochan. Actually
I have been reading about bit operators in Objective-C in Kochan's book, Programming in
Am reading the book Objective-C Programming by Big Nerd Ranch, and am not sure
I'm an Objective-C newbie and I'm reading iPhone programming by Alasdair Allan. While reading,
I'm reading Programming for Java Virtual Machine by Joshua Engel book where the author
I'm reading Programming Perl , and I found this code snippet: sub new {
I am reading Java Thread Programming a book by Paul Hyde .I am into
I have just started learning Objective-C, I am reading Programming in Objective-C 3rd Edition
I'm reading a book about iOS (it calls Programming iOS 4, by Matt Neuburg)
While reading Programming Ruby , I ran across this code snippet: while gets num1,

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.