![]() |
Calculator Multiple Operations?
I'm trying to program a basic calculator and have gotten all the operations working. Yet my problem is getting the calculator to perform multiple operations without having to hit the equal button in between each seperate operation. I'm listing the operations, and equal button code along with the global variables I used. If any one could help it would be greatly appreciated. Thanks.
:
string operation =""; |
If an operation button is pressed without entering a value, calculate the answer to the previous operation (don't display it) and treat it as if the user inputted it manually.
|
On an only semi-related note, you'll probably want to use a switch statement instead of your multiple ifs.
|
Thank you. I think I understand what you mean by calculate the answer to the previous operation without entering a value. Yet my problem now is with operations such as 1+2+4-5/2*3 operations like this will only perform the last operation I enter.
|
I think you need to create an instance object that will stores the total value (answer). And the total value should always be display after the equal button is press.
every the calculator performs calculations add the answer from the previous answer, but do not display it. [Just like Dameon said]. display the final answer on TextBox or Lable instance object that you created; The best idea to implement the final output in the "equal button event handler." but add the answer everytime it perform a calculations (added in the "x,+,-" event handeler that you created). I hope help. Good luck... if there any mistake on my post, please advise or correct me. Thanks, |
If you want to handle precedence properly, then things will get more complicated.
|
| All times are GMT -5. The time now is 12:33 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC