05-29-2010 02:43 AM
I am working on an assingment to build a simple calculator(+,-,/,*). I have put the buttons on the front panel by using the "ok" button under the boolean options. Since I am a beginner the pseudocode is of no help. Here is the assingment...
It will work in a similar fashion to handheld calculators. When you
press a number, it should appear in the RESULT field. When you press an operator (plus, minus,
times, divide), the number “0” should appear in the RESULT field. Finally, when you press the
equal button, the result of the preceding operation should appear in RESULT.
The front panel is shown below, along with a snapshot of the block diagram. Note that only one
of the events is shown, along with only one of the cases. You will need to construct the rest of
the VI using the pseudo-code given at the end of this document.
Your final VI will contain the following structures:
• 1 While loop
• 1 Event structure with 15 events
o 10 number events (0-9), 4 operator events (+ - / *), 1 “=” event
• 1 Case structure with 5 cases
o + - / * and “Default”
Hints:
• Make sure to put each button inside of its corresponding event case (See the “=” on the
block diagram below).
• Instead of a case structure with TRUE/FALSE cases, as we had in Assignment 7, this
case structure will depend on string values for each of the operators (+ - / *). You can
change the case value by left-clicking the text at the top of the structure. You can add
more events by right-clicking the structure and choosing “Add Case After/Before”.
Pseudo Code:
While: Stop button is not pushed
Old Result = New Result (Shift Register)
Old Stored Number = New Stored Number (Shift Register)
Old Operator = New Operator (Shift Register)
Event: (Timeout after 10 milliseconds)
Timeout:
New Result = Old Result (Number)
New Stored Number = Old Stored Number (Number)
New Operator = Old Operator (String)
Button “1” value change:
New Result = (Old Result*10)+1
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “2” value change:
New Result = (Old Result*10)+2
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “3” value change:
New Result = (Old Result*10)+3
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “4” value change:
New Result = (Old Result*10)+4
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “5” value change:
New Result = (Old Result*10)+5
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “6” value change:
New Result = (Old Result*10)+6
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “7” value change:
New Result = (Old Result*10)+7
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “8” value change:
New Result = (Old Result*10)+8
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “9” value change:
New Result = (Old Result*10)+9
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “0” value change:
New Result = (Old Result*10)+0
New Stored Number = Old Stored Number
New Operator = Old Operator
Button “+” value change:
New Result = 0
New Stored Number = Old Result
New Operator = “+”
Button “-” value change:
New Result = 0
New Stored Number = Old Result
New Operator = “-”
Button “*” value change:
New Result = 0
New Stored Number = Old Result
New Operator = “*”
Button “/” value change:
New Result = 0
New Stored Number = Old Result
New Operator = “/”
Button “=” value change:
New Stored Number = 0
New Operator = “”
Case:
Default
New Result = 0
Operator = “+”
New Result = Old Stored Number + Old Result
Operator = “-”
New Result = Old Stored Number – Old Result
Operator = “*”
New Result = Old Stored Number * Old Result
Operator = “/”
New Result = Old Stored Number / Old Result
End Case
05-29-2010 03:28 AM
ee7 wrote:I have put the buttons on the front panel by using the "ok" button under the boolean options.
ee7 wrote:
...
Your final VI will contain the following structures:
• 1 While loop
• 1 Event structure with 15 events
o 10 number events (0-9), 4 operator events (+ - / *), 1 “=” event
• 1 Case structure with 5 cases
o + - / * and “Default”
@ee7 wrote:
Since I am a beginner the pseudocode is of no help. Here is the assingment......
• Instead of a case structure with TRUE/FALSE cases, as we had in Assignment 7,
...
02-20-2011 09:23 PM
Hi folks,
I have a basic calculator function set up using a case structure. I have 5 settings on my slider. 0=Off, 1=add, 2= subtract, 3=multiply and 4=divide.
The 0 setting has an error message that requires the operator to select "OK".
Everything works fine until I throw a while loop around this so I can run it continuously. When 0 is selected it gets stuck in a loop with the prompt!
I am trying to insert another case structure that will use 0 as the default and then enable me to select the other four options.
Any hints or help would be appreciated.
02-20-2011 10:12 PM
Hello Sionach,
Appreciate if you could post your query in a new thread, since this could break the original post..