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

Username:   Password: 
 RegisterRegister   
 Checking An Array For Validity
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Archi




PostPosted: Sun Jul 20, 2003 6:53 pm   Post subject: Checking An Array For Validity

How would I go about checking to see if every part of an array is either valid or invalid. I'm going ot use this for my workshop type system for my game. And if every part of the array is " " or has nothing in it, then i don't want to give the user the option to use that part of the workshop. But if it does have something in it, then i'd like for that part to be shown.
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Sun Jul 20, 2003 6:59 pm   Post subject: (No subject)

as far as I know, you cannot check to see if a variable contains a value or not.

code:
var a: int
var ans: string
get ans
if ans = "y" then
   a+=1
end if


this simple piece of code gives a value to a if "y" is inputted as an answer. However, if something else is inputted, a will not be assigned a value.
In turing, you cannot check to see if a variable contains value or not.

also, what do you mean by valid? Could you specify that?

The best bet is to assign every element of the array a value, such as a blank, and when you compare value, if it's a blank, then you know it's invalid, again, I need a specific definition for valid.
Archi




PostPosted: Sun Jul 20, 2003 7:29 pm   Post subject: (No subject)

Well in the workshop, they combine 2 items together and if they have any gems they will also appear so that they can choose to use them... But if they don't have any, I don't want the array which would hold the gems in to appear.

So either the array would hold a gem name or just a " "
Dan




PostPosted: Sun Jul 20, 2003 8:28 pm   Post subject: (No subject)

i there are two ways i whould do this:

1. use two arrays, one with on or " " and one with what the room is

code:

var test : array 1 .. 5 of string
var partName: array 1..5 of string

partName(1) := "Main room"
partName(2) := "Computer room"
partName(3) := "Hacking room"
partName(4) := "Dan's room"
partName(5) := "Tony's room"

test(1) := "on"
test(2) := "on"
test(3) := " "
test(4) := " "
test(5) := "on"

put "open rooms: "

for i : 1 .. 5
    if test(i) not= " " then
        put partName(i)
    end if
end for


the othere way i whould use is to just use one with everything in it:

code:

var partName: array 1..5 of string

partName(1) := "Main room"
partName(2) := "Computer room"
partName(3) := " "
partName(4) := " "
partName(5) := "Tony's room"

put "open rooms: "

for i : 1 .. 5
    if partName(i) not= " " then
        put partName(i)
    end if
end for
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
krishon




PostPosted: Mon Jul 21, 2003 9:02 am   Post subject: (No subject)

lol, Dan told u asian
AsianSensation




PostPosted: Mon Jul 21, 2003 4:44 pm   Post subject: (No subject)

krishon wrote:
lol, Dan told u asian


huh? what? Dan told me how?
SilverSprite




PostPosted: Mon Jul 21, 2003 5:25 pm   Post subject: (No subject)

Dont act all innocent Asian.. hahahahaah
PaddyLong




PostPosted: Tue Jul 22, 2003 3:08 am   Post subject: (No subject)

a boolean fucntion for this would be good

code:

function validArray (checkThis : array 1 .. * of string) : boolean
    for q : 1 .. upper (checkThis)
        if checkThis (q) = " " then
            result false
        end if
    end for
    result true
end validArray
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  [ 8 Posts ]
Jump to:   


Style:  
Search: