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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:40:59+00:00 2026-05-23T04:40:59+00:00

I recently started following the online course on iPhone development from Stanford University on

  • 0

I recently started following the online course on iPhone development from Stanford University on iTunes U.

I’m trying to do the homework assignments now for the first couple of lectures. I followed through the walkthrough where I built a basic calculator, but now I’m trying the first assignment and I can’t seem to work it out. It’s a follows:

Your calculator already works with floating point numbers (e.g. if you press 3 / 4 =
it will properly show the resulting value of 0.75), however, there is no way for the user
to enter a floating point number. Remedy this. Allow only legal floating point
numbers to be entered (e.g. “192.168.0.1” is not a legal floating point number).

First of all, I’m not sure whether a floating point counts as digitPressed or operationPressed. I even tried with a new method called floatingPointPressed but that didn’t really work out. Could someone provide pointers on this?

When I saw it as digitPressed, I tried something like this:

    if (hasFloatingPoint) {
        NSRange range = [[display text] rangeOfString:@"."];
        if (range.location == NSNotFound) 
        {
            [display setText:[[display text] stringByAppendingFormat:digit]];
            hasFloatingPoint = YES;
        }
    }
    else {
        [display setText:[[display text] stringByAppendingFormat:digit]];
    }

But I’m missing the key concept here, I think.

I have also tried another solution which I have, sadly, undone already so I can’t provide the code but what happend was this: I could press a number, say 5 and then a floating point and 3 so I would end up with 5.3. I then managed to ‘disable’ the floating point for the remainder of the input.. But I guess I was a little too strict on it: I couldn’t, for example, put in 5.3.2 but after pressing an operation button (+, etc), it still wouldn’t let me press the floating point button. I guess I should reset the bool I used for this?

I’m not looking for a completely written out solution here, but could someone be so kind to provide some basic advice on how to tackle this problem? Some kind of step-by-step overview of what I should do and think about, without actually providing a code solution.

Thanks in advance.

  • 1 1 Answer
  • 3 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-23T04:41:00+00:00Added an answer on May 23, 2026 at 4:41 am

    Since you want a hint of where to look, have a look at attaching a NSNumberFormatter to the input fields.

    This is the proper way of validating input, rather than manually checking each character the user enters yourself.

    edit
    I’ve just read the assignment that you are trying to work through. I think my answer here, although still the right way to do it, not the best way to do what the assignment is trying to get you to do.

    Since you are reading the digits one by one as they are added to the view and appending them to the number you are operating on you may be on the right track with your original answer:

    • Keep accepting numbers as they are added
    • Add a decimalEntered flag – initialise it to ‘NO’
    • If a decimal is entered, check the flag, if it is no, accept it and set the flag to YES
    • If a decimal is entered and the flag is YES, don’t accept it.
    • Whenever you press an operand, set this flag back to NO.

    When you learn a bit more, you’ll realise that another way to do this is to let the user type in the field. Hook up a formatter to the field to validate that the input is a valid number, but it will also be able to turn the string into a number for you. And when an operand is pressed, this number will be kept aside as one of the numbers upon which the operand will operate.

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

Sidebar

Related Questions

I recently started following the online course on iPhone development from Stanford University on
I have recently started following the examples from The Little Schemer and when trying
I recently started to develop an iPhone App. Coming from C#, Objective-C has some
I just recently started looking into WatiN and was following the example from http://www.codeproject.com/KB/aspnet/WatiN.aspx
i'm getting the following, which recently started happening (from updates to the Twitter APi
I have recently started using Netbeans with following stack Liferay, icefaces with jBoss. Is
I’ve recently started learning IOCP on Windows and been reading the following article: http://www.codeproject.com/Tips/95363/Another-TCP-echo-server-using-IOCP
I have recently started programming in WPF and bumped into the following problem. I
I have recently started using Zend Studio which has reported as warning the following
Recently the PHP manual started showing the following warning on every mysql function page:

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.