Assignment 1 - CS193p for Fall 2011

200 views
Skip to first unread message

Fernando Crespo

unread,
Nov 22, 2011, 6:56:16 AM11/22/11
to iphone-appd...@googlegroups.com
Hi, could you guys enlighten me a little bit?

I'm watching CS193p for Fall 2011 in iTunes U.

I'm trying to implement PI as an operation but it's inserting in the stack twice.

So if I press 3 PI * the result is 9.8696 witch is actually the result of PI PI *!

Can somebody help a bit?

Where did you put the code to treat that? I think the best place is in popOperandOffStack, am I right?

Rob Todd

unread,
Nov 22, 2011, 9:51:23 AM11/22/11
to iphone-appd...@googlegroups.com
Yes, popOperandOffStack is the likely place for PI to go... are you hitting "enter" in between 3 and PI?  If not, then PI should be the only thing on the stack when the "*" operation is triggered and thus the result should be zero I would think because "*" is a two operand operation and there is only one operand on the stack.  

Maybe insert some NSLogs in to popOperandOffStack to see what the contents of the stack actually are during the recursion?

Rob

--
You received this message because you are subscribed to the Google Groups "iPhone Application Development Auditors" group.
To view this discussion on the web visit https://groups.google.com/d/msg/iphone-appdev-auditors/-/jmveWKQKx1sJ.
To post to this group, send email to iphone-appd...@googlegroups.com.
To unsubscribe from this group, send email to iphone-appdev-aud...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphone-appdev-auditors?hl=en.

Fernando Crespo

unread,
Nov 22, 2011, 11:33:46 AM11/22/11
to iphone-appd...@googlegroups.com
Thank you for the insight.

It happens that the performOperation command already fires enterPressed if the userIsInMiddleOfEnteringNumber, so pressing Enter between 3 and πis not really necessary. I guess it's entering that case when it shouldn't.

I'll make some logs and post back my results.

Fernando Crespo

unread,
Nov 24, 2011, 8:40:35 PM11/24/11
to iphone-appd...@googlegroups.com
I've managed to make it work!!! :-)

I had to remove the line that pushes the result onto the stack again.

//    [self.model pushOperand:result]; // Insert the result in the program

I've found this answer because it's how the RPN in Mac works.

I did the descriptionOfProgram too, my result for 5 E 3 + 6 + is shown as "((5 + 3) + 6" while the display shows 14 wich is the result.

MobileDevVT

unread,
Feb 16, 2012, 2:12:56 PM2/16/12
to iphone-appd...@googlegroups.com
I don't think you need to change pushOperand method. I have only changed performOperation: to implement Pi from Task 3 of the Assignment 1. You can find my solution at my blog. Not sure if it's correct but it is mine.
http://mobiledevvt.blogspot.com/2012/02/cs193p-fall-2011-iphone-application.html
Reply all
Reply to author
Forward
0 new messages