Posted: Thu Jan 13, 2011 6:10 pm Post subject: Calculator Questions
What is it you are trying to achieve?
I am trying to create a basic calculator.
What is the problem you are having?
Hey guys, thanks to your help, i have created a basic calculator. it still has a few bugs that i would like to fix.
1) Right now, the calculator can only do single digit operations. like 6 /8 = 0.75. What should i do so that calculator can recognize i entered the number 123 instead of 1, then clearing the number, 2 then clearing the number, and then 3, then clearing the number.
2) I need help with a part of the program that clears a certain parameter of data when a certain button is pressed. The creating the button is easy, but how do you make it so when the button is clicked it only clears a certain part of the screen. Is that even possible?
3) For my calculator, you have to enter the two numbers then the operator to do the calculations. How do you make it so that you have to enter the first number, then the operator, and then the second number to do the calculations.
For 1) my teacher told me that i have to do some sort of storage technique but it was a bit confusing. can you guys elaborate?
Describe what you have tried to solve this problem
i tried creating a new variable to store the answer, but it did not work.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
available upon request
Please specify what version of Turing you are using
4.1.1
Sponsor Sponsor
Tony
Posted: Thu Jan 13, 2011 6:35 pm Post subject: RE:Calculator Questions
1 and 3 are the same thing, and your teacher is right -- you need to keep track of what state you are in right now. For example, "entering the first number"; while in this state, every digit pressed gets added to the first number being entered.
2 -- clearing means drawing something new on top. You can draw something new in just one part of the screen.
Posted: Thu Jan 13, 2011 6:42 pm Post subject: RE:Calculator Questions
1 and 3-but my calculator has a button type interface, so if i enter a number, it will only show that number. and by state, you mean creating a new variable that keeps track if it is in this state or not?
2- but i want to clear only a certain paramters of the code x and y, coordinates. oh i get it, do i have to do something like if this button is clicked, cls this part of the screen?
Tony
Posted: Thu Jan 13, 2011 6:46 pm Post subject: RE:Calculator Questions
Posted: Thu Jan 13, 2011 7:39 pm Post subject: RE:Calculator Questions
never mind man i just solved the 2nd one . ok for the first question, i just created a state variable,
and if it 0 then it will do single digit operations. if state is 1, it will do triple or digit operations. but how? do i have to put num, num? or num, num2?
Tony
Posted: Thu Jan 13, 2011 7:43 pm Post subject: RE:Calculator Questions
You have clicked the first number. You have a copy of that single digit in num1, and you are in a state that describes this situation.
You click on another digit. What needs to happen to num1 and what needs to happen to the state?
How about if you click on an operator, such as "+"?