Create a application that acts as a simple calculator. Create buttons for 0-9 an
ID: 3746971 • Letter: C
Question
Create a application that acts as a simple calculator. Create buttons for 0-9 and a text field that displays the concatenation of the current digits as they are clicked. Add buttons for operators “+”, “-“, “*”, and “/”. Add a final button for “=” that calculates the computed value with the value entered in the text field. For instance, clicking buttons 7, +, 8, = should display 15. Need help writing Pseudocode. Create a application that acts as a simple calculator. Create buttons for 0-9 and a text field that displays the concatenation of the current digits as they are clicked. Add buttons for operators “+”, “-“, “*”, and “/”. Add a final button for “=” that calculates the computed value with the value entered in the text field. For instance, clicking buttons 7, +, 8, = should display 15. Need help writing Pseudocode.Explanation / Answer
As you need help writing the psedocode, I will discuss the logic .
There will be a form in your html file(as you have mentioned nothing, i will write it in html)
The form will have several buttons.
First i will write the front end button creation code. For computation will only write the pseudocode, as you want help with that.
This will create your Html front end.
Now we i will explain how to write the pseudocode for computation -
//strings to calculate the operations
string s1 = " ";
string s2 = " ";
//now make a list of operands and operators
operands [] = {0,1,2,3,4,5,6,7,8,9,'.'};
operators[] = {'+', ' - ', '*', '/'};
//check keyboard input
current_operator = " "
check input :
if input == 'R' :
s1 = " "
s2 = " "
current_operator = " "
else if input == "=" : // calculation for equal sign
if current_operator == " " || s2 == " " :
print(s1) // current operator or s2 is not assigned then print s1
else :
if (current_operator == '+') :
s1 = str(int(s1) + int(s2)) // print addition of the two entries
else if (current_operator == '-') :
s1 = str(int(s1) - int(s2)) // print subtraction of the two entries
else if (current_operator == '*') :
s1 = str(int(s1) * int(s2)) // print multiplication of the two entries
else if (current_operator == '/') :
if int(s2) == 0 :
print(NAN) // taking care of zero division error
else :
s1 = str(int(s1) / int(s2)) // print division of the two entries
// if you want to take care of float inputs use float in place of int
print(s1) // give the output
s2 = " " // empty s2
current_operator = " " // empty current_operator
else if input in operators : //checking if the input belongs to the operator array elements
if s1 == " " : // discard the input (do nothing because there is no operand before it)
else if s2 == " " :
current_operator = input // (second string is empty then we just store it in current _operator list)
else :
if (current_operator == '+') :
s1 = str(int(s1) + int(s2)) // print addition of the two entries
else if (current_operator == '-') :
s1 = str(int(s1) - int(s2)) // print subtraction of the two entries
else if (current_operator == '*') :
s1 = str(int(s1) * int(s2)) // print multiplication of the two entries
else if (current_operator == '/') :
if int(s2) == 0 :
print(NAN) // taking care of zero division error
else :
s1 = str(int(s1) / int(s2)) // print division of the two entries
// if you want to take care of float inputs use float in place of int
s2 = " " // empty s2
current_operator = input
if input in operands :
if current_operator == " " :
s1 += input
// if no current operator present then the input will be added to s1
// else it will be added to s2.
else :
s2 += input