calculator
Author |
Message |
yodu123
|
Posted: 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

|
|
 |
DemonWasp
|
Posted: 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

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

|
Posted: 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.
|
Posted: 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

|
Posted: 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.  |
|
|
|
|
 |
Tony

|
Posted: 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 |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
andrew.
|
Posted: 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

|
|
 |
Tony

|
|
|
|
 |
|
|