Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Calculator Questions
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3, 4  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Wajih




PostPosted: 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
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: 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




PostPosted: Thu Jan 13, 2011 6:46 pm   Post subject: RE:Calculator Questions

yes and yes.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Thu Jan 13, 2011 7:04 pm   Post subject: RE:Calculator Questions

1 and 3- kk i get it. so it will be like

if state = 1 then
so and so
else do the single digit operation.

20 its clearer to me but do i have to be like

if button = 1 and so and so then
cls ( x1, y1, x2, y2)
end if.

that doesnt seem right because i think the cls will clear the whole screen instead of the certain parameters
Wajih




PostPosted: Thu Jan 13, 2011 7:06 pm   Post subject: RE:Calculator Questions

2-*
Tony




PostPosted: Thu Jan 13, 2011 7:15 pm   Post subject: RE:Calculator Questions

you can read the build in documentation or our copy of it here -- cls
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Thu Jan 13, 2011 7:19 pm   Post subject: RE:Calculator Questions

alright i read it, but how do i change the row and column?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jan 13, 2011 7:25 pm   Post subject: RE:Calculator Questions

of the cursor? locate(r,c)

Did you read this part?
Quote:

The entire output window is set to the current text background color


Hint: cls is probably not what you are looking for.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Thu Jan 13, 2011 7:29 pm   Post subject: RE:Calculator Questions

oh so the if i do cls, it clears the entire thing since the background is white. do you know where to find what i am looking for? erase, delete?
Tony




PostPosted: Thu Jan 13, 2011 7:38 pm   Post subject: Re: RE:Calculator Questions

Tony @ Thu Jan 13, 2011 6:35 pm wrote:

2 -- clearing means drawing something new on top. You can draw something new in just one part of the screen.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Thu Jan 13, 2011 7:39 pm   Post subject: RE:Calculator Questions

never mind man i just solved the 2nd one Very Happy. 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




PostPosted: 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 "+"?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Wajih




PostPosted: Thu Jan 13, 2011 7:52 pm   Post subject: RE:Calculator Questions

so i am in state = 1.
num1 becomes the first number after the second digit i click. if state = 1 then i should add to the num1?
Tony




PostPosted: Thu Jan 13, 2011 8:06 pm   Post subject: RE:Calculator Questions

if state = 1 describes a situation where you are "still entering num1", then yes, the second digit needs to be included.

The tricky parts are the transitions. How do you get to state = 2 and what does it mean? Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 4  [ 55 Posts ]
Goto page 1, 2, 3, 4  Next
Jump to:   


Style:  
Search: