General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 5th, 2012, 10:48 AM
apdz94 apdz94 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 1 apdz94 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 33 sec
Reputation Power: 0
Pep8 calculator help!

Is anyone here good with Pep8? I've been assigned a midyear project (with a friend) where we have to create a calculator with Pep8. We know how to subtract and add two different inputs in separate programs, but we can't seem to figure out how to make a program that will add when we input "+" and subtract when we input "-" (in the same program of course). For example, if we input 6-2, it will output 4, but also if we input 6+2, it will output 8. Any help/insight would be appreciated. Below is our codes for addition and subtraction, and what we have so far (this is only the tip of the iceberg...). Cheers!

Here is the code for addition:

deci num1,d; gets 1st input
lda num1,d; loads first number into accumulator
deci num2,d; gets 2nd input
adda num2,d; adds 2nd input to accumulator
sta num1,d; stores num1 into accumulator
BRV overflow,i; branch to stop
deco num1,d; output result in accumulator
stop
overflow: .ASCII "Error!\x00"
stop
num1: .word 0x0000
num2: .word 0x0000
.end

...and subtraction:

deci num1,d; get 1st input
lda num1,d; loads first number into accumulator
deci num2,d;gets 2nd input
suba num2,d;subtracts num2 from accumulator
sta num1,d; stores num1 into accumulator
BRV overflow,i;branch to stop
deco num1,d; output result in accumulator
stop
overflow: .ASCII "Error!\x00"
stop
num1: .word 0x0000
num2: .word 0x0000
.end

----

Thanks!

-Anokh and David

~

P.S. As we said, this was just the tip of the iceberg. Here is the entire assignment in case anyone is interested in looking it over. Each milestone awards points, and we aim to complete at least 6 milestones.

1 +/- Lines The user enters a number, then a plus or minus, then another number, and the program outputs the sum. Report an error if the user enters something besides a + or – as the operator. Each entry is on a separate line (the user presses Enter after each one). For example:
34
+
2
=36
-2
-
4
=-6
3
*
3
Error: invalid expression
Note that this allows you to use DECI and CHARI.
2 Detect Overflow Detect and report any two’s complement overflow as an error. For example:
32767
+
~~~~~~~~~~~~~~~~~~~~~~~~
2
Error: overflow
32768
Error: overflow
-32768
-
1
Error: overflow
~~~~~~~~~~~~~~~~~~~~~~~~
3 Multiply Support * for multiply, including positive and negative numbers. Detect and report overflow as an error.
~~~~~~~~~~~~~~~~~~~~~~~~
4 Divide Support / for divide, including positive and negative numbers. Detect and report division by zero as an error.
~~~~~~~~~~~~~~~~~~~~~~~~
5 Use Answer Save the result of the last operation, and use it if the user enters an operator first. It is only an operator if it is the only thing entered on the line; otherwise, it is the positive or negative sign. Note that this means you are going to have to use CHARI for the first input, and if it’s a number, create an integer from the string of characters entered, including detecting overflow and invalid characters!
~~~~~~~~~~~~~~~~~~~~~~~~
6 n op n From here on, use a single line to enter the complete expression to be evaluated, and you do NOT need to support the “Use Result” function, but you must continue to detect and report overflow and division by 0.
For this Milestone, the valid expressions are a single digit, followed by a +, -, * or /, and then another single digit. No spaces are allowed. Detect and report any invalid expression.
~~~~~~~~~~~~~~~~~~~~~~~~
7 num op num Allow multi-digit numbers, including leading + or – signs. There is no separate “negative” sign like the TI calculator has; for example:
+3--4
=7
3+-4
=-1
~~~~~~~~~~~~~~~~~~~~~~~~
8 multi-op Allow any number of operators strung together, but simply done in order (ignoring PMDAS). For example:
3+4*3
=21
~~~~~~~~~~~~~~~~~~~~~~~~
9 MDAS Apply the usual order-of-operations rules:
3+4*3
=15
2*3+2+4*3
=20
This can be done without a stack, but it’s probably easier with one, and you’re going to need it for the next Milestone anyway.
~~~~~~~~~~~~~~~~~~~~~~~~
10 PMDAS Add parentheses. Any number of parentheses are allowed:
(2)
=2
(((2+3)))
=5
~~~~~~~~~~~~~~~~~~~~~~~~
11 Use Answer 2 Add back in the Use Answer feature. A single leading + or – is treated as an operator on the previous answer; to enter a negative number, the user needs to use parentheses or subtract from 0:
3
=3
-5
=-2
0-8
=-8
(-10)
=-10

Once again, we aren't asking you to do the project, we just need assistance on the first milestone in order to set a foundation for the rest of the project. Starting is the most difficult part.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Pep8 calculator help!


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap