Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

:helo an somebody help me with these question:write calculator program that prompts the user to enter a single calculation using multiplication, division, addition, or subtraction.when the usrer press enter the calculation is made, and the result is displayed.

OpenStudy (anonymous):

its really simple man you have to lay out your input pyour process then the output using th tool based on your programming language input choices subtraction addition mult input 2 numbers in this case use a tool that prompts u to enter two numbers process based on whats selected from 1 and 2 if its addition then it will be c=a+b output then use output tool or command to print out c or the result

OpenStudy (anonymous):

If i understand this right; your program should receive the input like this: "2+4/2+3*9"<ENTER> Then program calculates and solves the equation, giving you the product output : "2+4/2+3*9 = 31" Now, firstly you should receive the input as a "string". That would make things easier. Once received the input, we'll check if it is malicious (for example, did the user made some typos?). If input is malicious, re-prompt and re-receive another input from the user until its true (i would use a do-while loop) When we receive the input correctly, we'll split it to parts and calculate recursively, regarding to operator precedence. To do that, we'll seek for divisions and calculate them, until they're finished. Then we'll do the same thing in the order of Multiplications, Subtractions and Additions. This is basically how our program works. I'll write a code for this ASAP, but i think you can understand what i'm suggesting. Thanks for your time & reading.

OpenStudy (anonymous):

I think you're only looking for simple calculations with two terms: 3+4 4-9 18*32 100/7 I don't know what language you're supposed to use, but here are the important methods from Java. String.indexOf(char c): Use this to search for each of the operators you need to handle. When you find one, remember the index of where it was found. Also remember which operator you found. String.substring(start, [end]): Using the index from above, split the string into two substrings: the left part and the right part. String.trim(): removes whitespace from the beginning and end of a string. Integer.parseInt(s)/Double.parseDouble(s): Turns a string into an integer or a double. I don't know if you need to support doubles, but if you do, there's the method. Once you collect these pieces of data (left value, right value, operator), evaluate the expression and print the result.

OpenStudy (anonymous):

In Python 2.x: # calculator.py # Get and evaluate an equation equation = raw_input("Enter an equation: ") result = eval(equation) print result

OpenStudy (anonymous):

In Python 3: # calculator.py # Calculate an equation equation = input("Enter an equation: ") result = eval(equation) print(result)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!