Computer Science Canada

Proper School Violence Test for Gr10 Students

Author:  sylvester-27 [ Fri Dec 09, 2005 11:24 am ]
Post subject:  Proper School Violence Test for Gr10 Students

Heres the pictures sorry it took so long

Author:  Tony [ Fri Dec 09, 2005 12:54 pm ]
Post subject: 

not without pictures it doesn't.. if you're not going to upload the complete application, at least don't let the program crash in absense of some data. I especially want to see that squirrelfight.bmp

anyways, I was going to say that
code:

var c1y, c1n, c2y, c2n, c3y, c3n, c4y, c4n, c5y, c5n, c6y, c6n, c7y, c7n, c8y, c8n : real

looks plain ugly.

Author:  codemage [ Fri Dec 09, 2005 12:56 pm ]
Post subject: 

It won't run without having the image files included.

If you just want people to check out your code for issues, and if the pictures aren't critical to doing the test, you can %comment out the picture drawing and upload a text-only version.

Otherwise, make the pictures available.

Author:  djlenny_3000 [ Fri Dec 09, 2005 1:39 pm ]
Post subject: 

Try Arrays

instead of

code:
var c1y, c1n, c2y, c2n, c3y, c3n, c4y, c4n, c5y, c5n, c6y, c6n, c7y, c7n, c8y, c8n : real


Try
code:
var cy:array 1..8 of real
         var cn:array 1..8 of real


allot nicer to read in my opinion

Author:  codemage [ Fri Dec 09, 2005 2:58 pm ]
Post subject: 

Or have a counter to count how many people took the survey, and only record "yes" answers - preferably in an array.

That'll cut back on about half of your variables.

Author:  Cervantes [ Fri Dec 09, 2005 5:32 pm ]
Post subject: 

djlenny_3000 wrote:
Try Arrays

instead of

code:
var c1y, c1n, c2y, c2n, c3y, c3n, c4y, c4n, c5y, c5n, c6y, c6n, c7y, c7n, c8y, c8n : real


Try
code:
var cy:array 1..8 of real
         var cn:array 1..8 of real


allot nicer to read in my opinion

code:

var c : array 1 .. 8 of
    record
        x, y : real
    end record

Yuuup.

Author:  sylvester-27 [ Thu Dec 22, 2005 12:35 pm ]
Post subject: 

i tried to use the arrays but it did not recognize it. said that the variables were not declared. also how do i zip stuff so i can put the pics in too?.

Author:  Unisyst [ Thu Dec 22, 2005 1:19 pm ]
Post subject: 

Right-click -> New -> Zipped folder (dont know exactly what it's called because I use WinRar).

Note: This is only for Windows XP.

Author:  sylvester-27 [ Wed Jan 11, 2006 10:36 am ]
Post subject: 

there i put the pictures in if anyone wants them

Author:  Clayton [ Wed Jan 11, 2006 7:30 pm ]
Post subject: 

to declare your array simply put the array into a for ex.

var cn,cy:array 1..8 of real

for i:1..8
cn(i):=10
cy(i):=5
end for

give that a whirl Laughing

Author:  sylvester-27 [ Thu Jan 12, 2006 12:01 pm ]
Post subject: 

I get how the array would work but whenever I put in an array it keeps telling me that my variables have not been declared. So i might as well just leave it as messy code if it works fine.

Author:  Delos [ Thu Jan 12, 2006 3:25 pm ]
Post subject: 

SuperFreak82 wrote:
to declare your array simply put the array into a for ex.

var cn,cy:array 1..8 of real

for i:1..8
cn(i):=10
cy(i):=5
end for

give that a whirl Laughing


Not quite. That would be how you would initialize your elements in your array. Declaration occured at the 'var cn, cy...' part.
As for the non-declaration message, are you sure you're calling the index at the same time?

Turing:

var myArray : array 1..10 of int
for i : 1 .. upper (myArray)
   myArray := Rand.Int (1, 5)
end i
% Will not work.
% However:
for i : 1..upper (myArray)
   myArray (i) := Rand.Int (1, 5)
end for
% Will work since you've actually specified which element in 'myArray' you're referring to.


A general piece of advice in cases like these is to attempt to recreate the specific error message in a much simpler piece of code. This is particularly useful when you have masses and masses of coding to sift through - knowing about what you're looking for is like adding a strobe light to that proverbial needle in that aggrevating haystack.

wtd says it best: "Just because you shouldn't do something, doesn't mean you shouldn't know how to."

Author:  sylvester-27 [ Fri Jan 13, 2006 8:40 am ]
Post subject: 

there would be a simpler way to do it. I think the reason that the array doesn't work is because my variables are c1y, c1n and so on. The array won't work because
var cy, cn : array 1..8 of real
will assign the variable as cy1 and cn1. so the array would work if I wanted to go through all my code and change it.

Author:  Cervantes [ Fri Jan 13, 2006 1:34 pm ]
Post subject: 

No sylvester-27, arrays do work in Turing. You're just using them wrong. Look at the code Delos posted, or look at a tutorial (see Turing Walkthrough for link).

If you declare an array
code:

var cn : array 1 .. 8 of int

You don't access the elements by
code:

cn1

cn1 is a standard variable name, and you haven't declared that variable. Rather, you access the element of the cn array:
code:

cn (1)


: