Author |
Message |
ynotpeace
|
Posted: Wed Dec 09, 2009 2:01 pm Post subject: Error when using math with ints. |
|
|
What is it you are trying to achieve?
here is a basic line of code i did using 3 variables ( all integers)
What is the problem you are having?
the int "cases" is highlighted and the error is: "assigned value is the wrong type"
Describe what you have tried to solve this problem
I've tried everything i can think of...
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
avg := casetot / 10 - cases
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
DemonWasp
|
Posted: Wed Dec 09, 2009 2:12 pm Post subject: RE:Error when using math with ints. |
|
|
...and what types do the variables avg, casetot and cases have? There are plenty of combinations that just won't work, and you haven't provided us nearly enough information here (we need to see the variable declarations). |
|
|
|
|
 |
TheGuardian001
|
Posted: Wed Dec 09, 2009 2:38 pm Post subject: Re: Error when using math with ints. |
|
|
Actually I believe the int type in turing just flat out rejects the / operator unless you round it.
if you want to use division with ints, use div, which will automatically round it. |
|
|
|
|
 |
ynotpeace
|
Posted: Wed Dec 09, 2009 2:39 pm Post subject: Re: Error when using math with ints. |
|
|
sorry about that.
I'm new to this
heres the declorations:
Turing: |
var cases : int
var avg : int
var casetot: int := one+two+three+four+five+six+seven+eight+nine+ten
var one: int := 100
var two: int := 500
var three: int := 1000
var four: int := 5000
var five: int := 10000
var six: int := 25000
var seven: int := 50000
var eight: int := 100000
var nine: int := 500000
var ten: int := 1000000
|
here is my whole code ( i dont think you'll understand the purpose of this code though):
Turing: |
var one: int := 100
var two: int := 500
var three: int := 1000
var four: int := 5000
var five: int := 10000
var six: int := 25000
var seven: int := 50000
var eight: int := 100000
var nine: int := 500000
var ten: int := 1000000
var cases : int
var avg : int
var casesdone : int
var banker : int
var counter : int := 1
var casetot: int := one+two+three+four+five+six+seven+eight+nine+ten
get cases
loop
get casesdone
if casesdone = 1 then
casetot := casetot - one
elsif casesdone = 2 then
casetot := casetot - two
elsif casesdone = 3 then
casetot := casetot - three
elsif casesdone = 4 then
casetot := casetot - four
elsif casesdone = 5 then
casetot := casetot - five
elsif casesdone = 6 then
casetot := casetot - six
elsif casesdone = 7 then
casetot := casetot - seven
elsif casesdone = 8 then
casetot := casetot - eight
elsif casesdone = 9 then
casetot := casetot - nine
elsif casesdone = 10 then
casetot := casetot - ten
end if
counter := counter + 1
exit when counter = cases + 1
end loop
get banker
avg := casetot / 10 - cases
if avg > banker then
put "no deal"
elsif avg <= banker then
put "deal"
end if
|
|
|
|
|
|
 |
ynotpeace
|
Posted: Wed Dec 09, 2009 2:41 pm Post subject: Re: Error when using math with ints. |
|
|
Thank you guardian ^.^ |
|
|
|
|
 |
mirhagk
|
Posted: Wed Dec 09, 2009 4:09 pm Post subject: RE:Error when using math with ints. |
|
|
just a tip, read up on arrays. instead of
Turing: |
var one: int := 100
var two: int := 500
var three: int := 1000
etc...
|
you can do the following
Turing: |
var num:array 1..10 of int
num(1):=100
num(2):=500
etc...
|
or better yet
Turing: |
var num:array 1..10 of int:=init (100,500 etc...)
|
(also you can just do the following)
instead of
|
|
|
|
|
 |
|