
-----------------------------------
darknoob
Wed Mar 29, 2006 8:25 pm

Trouble compiling program.
-----------------------------------

var number : string 
var located : int := 1 
var intnumber : int :=0 
var realnumber : real :=0 
var rea11 : int := 0 
var decimal : int := 0 
var add : int := 0 

get number 

for i : 1 .. length (number) 
if ord (number (i)) = 46 then 
decimal := i 
rea11 := 1 
end if 
end for 

if rea11 = 1 then 
if length (number) = 3 then 
if decimal = 1 then 
located :=2 
realnumber := realnumber + ((ord (number ( located )) -48 / 10) 

located :=3 
realnumber := realnumber + ((ord (number ( located )) -48) / 100) 
elsif decimal =2 then 
located :=1 
realnumber :=realnumber + ((ord (number ( located )) -48 
located :=3 
realnumber := realnumber + ((ord (number ( located )) -48 / 10)) 

elsif decimal =3 then 
located :=1 
realnumber := realnumber + ((ord (number ( located )) -48) * 10)
located :=2 
realnumber := realnumber + ((ord (number ( located )) -48)) 
end if 
end if 

put realnumber 
else 
if length (number) = 1 then 
located := 1 
intnumber := intnumber + ord (number (located)) -48 
elsif length (number) =2 then 
located :=1 
intnumber := intnumber + ord (number (located)) -48 
elsif length (number) = 2 then 
located :=1 
intnumber := intnumber + ((ord (number (located)) -48) * 10) 
located := 2 
intnumber := intnumber + ((ord (number (located)) -48)) 
elsif length (number) = 3 then 
located :=1 
intnumber := intnumber + ((ord (number (located)) -48) * 100) 
located :=2 
intnumber := intnumber + ((ord (number (located)) - 48) * 10) 
located :=3 
intnumber := intnumber + ((ord(number (located)) -48)) 
elsif length (number) = 4 then 
located :=1 
intnumber :=intnumber + ((ord(number (located)) -48) *1000) 
located :=2 
intnumber :=intnumber + ((ord(number (located)) -48) *100) 
located :=3 
intnumber :=intnumber + ((ord(number (located)) -48) *10) 
located :=4 
intnumber :=intnumber + ((ord(number (located)) -48)) 
end if 
put intnumber 
end if


-----------------------------------
darknoob
Wed Mar 29, 2006 8:26 pm


-----------------------------------
i donno what is wrong, every time i try to run it it always say error on 'located'

-----------------------------------
HellblazerX
Wed Mar 29, 2006 8:31 pm


-----------------------------------
the problem is the variable located, but the line before that

for the line
realnumber := realnumber + ((ord (number (located)) - 48 / 10)
you missed a bracket at the end.  change it to:
realnumber := realnumber + ((ord (number (located)) - 48 / 10))
and for the line
realnumber := realnumber + ((ord (number (located)) - 48
you're missing 2 brackets, so change it to:
realnumber := realnumber + ((ord (number (located)) - 48))
it should work after that.

-----------------------------------
darknoob
Wed Mar 29, 2006 8:36 pm


-----------------------------------
hmm...but what should i do?
when i run the program, everything (for example 45+44) it always turn out to be 0
what should i do??

-----------------------------------
person
Wed Mar 29, 2006 8:39 pm


-----------------------------------
a) indent ur code
b) this is almost the exact same code as: http://www.compsci.ca/v2/viewtopic.php?t=11677
c) y dont u read the error message turing gives u?
d) tell us wat ur program is supposed to do

-----------------------------------
HellblazerX
Wed Mar 29, 2006 8:40 pm


-----------------------------------
wut is your program suppose to do?

-----------------------------------
darknoob
Wed Mar 29, 2006 8:43 pm


-----------------------------------
hmm...i know that guy!!!0_o 
message says unnamed #1 finished execution, nothing about what is wrong
the run window says this when i try to run it

35+45
0


-----------------------------------
darknoob
Wed Mar 29, 2006 8:45 pm


-----------------------------------
the program is suppose to read and decode a simple mathematical expression given as a string

-----------------------------------
darknoob
Wed Mar 29, 2006 8:54 pm


-----------------------------------
i still get 0 after i changed all the stuff

-----------------------------------
HellblazerX
Wed Mar 29, 2006 8:54 pm


-----------------------------------
in that case, why don't you just use the strint function to convert the String into an int, and perform the operations on the int, instead of getting the ASCII value of the number, and working with those.

-----------------------------------
darknoob
Wed Mar 29, 2006 8:56 pm


-----------------------------------
hmm...i'm really new at programing >_< just started this year

-----------------------------------
person
Wed Mar 29, 2006 9:06 pm


-----------------------------------
Try using the debugger menu to find whats wrong

-----------------------------------
darknoob
Wed Mar 29, 2006 9:09 pm


-----------------------------------
i told u i'm really new to this turing thing and i dont know anything about it, just want to pass computer science and move on @_@
how u use the debug menu...T-T

-----------------------------------
darknoob
Wed Mar 29, 2006 9:12 pm


-----------------------------------
it says i got error on the second last line...at least that is what i think it says -_-

-----------------------------------
HellblazerX
Wed Mar 29, 2006 9:19 pm


-----------------------------------
try this code instead:

var num1 : real
var num2 : real
var operator : string
var number : string

get number

for i : 1 .. length (number)
    if strintok (number (i)) = false and ord (number (i)) not= 46 then
        num1 := strreal (number (1 .. (i - 1)))
        operator := number (i)
        num2 := strreal (number ((i + 1) .. *))
    end if
end for

if ord (operator) = 43 then
    put num1 + num2
elsif ord (operator) = 45 then
    put num1 - num2
elsif ord (operator) = 42 then
    put num1 * num2
elsif ord (operator) = 47 then
    put num1 / num2
end if

basically, this code takes in the String input, and divides the String up based on where the operator is, the substring that cannot be converted to int.  The first half is the first number, and the second half is the second number, and the operator is recorded.  Then, the appropriate operation is performed based on the what operator is used.  This code doesnt have any error checking, so its easy to crash if you add in spaces and other stuff

-----------------------------------
darknoob
Wed Mar 29, 2006 9:20 pm


-----------------------------------
nice
thx

-----------------------------------
chrispminis
Thu Mar 30, 2006 12:03 am


-----------------------------------
Err darknoob dont use it. I'm probly in your class and the assigment said specifically NOT to use predefined Turing functions such as strint or strintok. That's why we spent so many classes emulating the strreal function. There have been a billion topics on this subject, all by people you know, because we are the only school in the world with this assignment right now.

-----------------------------------
MysticVegeta
Thu Mar 30, 2006 8:54 pm


-----------------------------------
I find this to be pretty dumb. Why would someone block from using predefined fcns? to increase logic/skills? Heck, there are other ways, make them do J4 on CCC lol. Anyways, if you find the topic by chrispminis, you will find how to convert it without using those fcns.

-----------------------------------
person
Thu Mar 30, 2006 9:19 pm


-----------------------------------
Why would someone block from using predefined fcns? to increase logic/skills? 

Yes. I don't understand why this would be a bad way of teaching students about concepts.
