title: CS193P - Adding floating point button to iOS calculator
body: <p>I recently started following the online course on iPhone development from Stanford University on iTunes U.</p>
  
  <p>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:</p>
  
  <p><em>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).</em></p>
  
  <p>First of all, I'm not sure whether a floating point counts as <code>digitPressed</code> or <code>operationPressed</code>. I even tried with a new method called <code>floatingPointPressed</code> but that didn't really work out. Could someone provide pointers on this?</p>
  
  <p>When I saw it as digitPressed, I tried something like this:</p>
  
  <pre><code>    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]];
      }
  </code></pre>
  
  <p>But I'm missing the key concept here, I think.</p>
  
  <p>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 <code>5</code> and then a floating point and <code>3</code> so I would end up with <code>5.3</code>. 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 <code>5.3.2</code> but after pressing an operation button (<code>+</code>, etc), it still wouldn't let me press the floating point button. I guess I should reset the bool I used for this?</p>
  
  <p>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. </p>
  
  <p>Thanks in advance.</p>