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

Username:   Password: 
 RegisterRegister   
 calculator
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
yodu123




PostPosted: Mon Apr 13, 2009 10:57 am   Post subject: calculator

would someone give me the idea on how i can make a calculator on turing? especially how i cna make it solve 2*2(1-5+3)/5 kind of problems
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Mon Apr 13, 2009 2:57 pm   Post subject: RE:calculator

If you want to solve a complicated expression like 2*2*(1-5+3)/5, you'll probably have to either learn about parsing properly, or make a really hackish version of it. I've done both.

If you want to learn all about parsing, it's an involved subject, but well worth learning about. You'll run a few methods on that statement and get something called a "parse tree" which you can use to evaluate the statement. If you don't know what a tree is in the computer science sense, you should probably choose a simpler program.

The hackish way is done in-place, with strings and a lot of conversion between integers and strings. I won't go into detail because I value what little remains of my sanity.
Insectoid




PostPosted: Mon Apr 13, 2009 3:34 pm   Post subject: RE:calculator

DemonWasp, the latter is exactly the way I'm doing my calculator. It is rather frustrating, however no more or less difficult than a parse tree. Either way, it is very difficult without a half year of programming experience under your belt.
tjmoore1993




PostPosted: Mon Apr 13, 2009 3:48 pm   Post subject: RE:calculator

Turing:

var number1, number2, answer : real
loop
cls
put "First Value : "..
get number1
put "Second Value : "..
get number2
answer := number1 + number2
put answer
delay (2000)
end loop


There are many ways of creating a calculator. This one of the ways that are tought to students in highschool all around canada. Although it is not efficient, it can still show students another way of thinking about things.

If you want to go about having more equations then think about adding an if statement along with the code given above.
andrew.




PostPosted: Mon Apr 13, 2009 3:59 pm   Post subject: RE:calculator

You would have to make your program look at the given expression and figure our what to do first, second, third, etc. That is the hard part. After that, then all you have to do is add, subtract, multiply, etc. with the numbers.
tjmoore1993




PostPosted: Mon Apr 13, 2009 8:01 pm   Post subject: Re: RE:calculator

andrew. @ Mon Apr 13, 2009 3:59 pm wrote:
You would have to make your program look at the given expression and figure our what to do first, second, third, etc. That is the hard part. After that, then all you have to do is add, subtract, multiply, etc. with the numbers.


A calculator can get very easy if you bring it down.

Using some sort of counter can help a lot. Smile
Tony




PostPosted: Mon Apr 13, 2009 8:10 pm   Post subject: RE:calculator

It's even easier to make a "calculator" that has only one functionality: spelling 80085
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
andrew.




PostPosted: Mon Apr 13, 2009 8:13 pm   Post subject: Re: RE:calculator

Tony @ Mon Apr 13, 2009 8:10 pm wrote:
It's even easier to make a "calculator" that has only one functionality: spelling 80085
Haha. We used to do stuff like that in grade 5.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Apr 13, 2009 8:29 pm   Post subject: RE:calculator

My point exactly 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 1  [ 9 Posts ]
Jump to:   


Style:  
Search: