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

Username:   Password: 
 RegisterRegister   
 help with calling record
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ejoman3002




PostPosted: Thu Apr 19, 2007 2:04 pm   Post subject: help with calling record

hey. im making a phone book program for class and i need help.

basicly im making a phone book program and 1 of the options i put is if the user wants to look up the persons info by whatever info they choose. such as if they wana look up someone whos name is bob. but they also have the option to search by last name, address, phone numbers..... so on. so the code to do that looks like this on my program

Quote:

if search="first name" then
put" whats the persons first name"
get search2
for decreasing i:friendnum..1
if search2=info(i).firstname then
infogive (i)
end if
end for


i want firstname in "info(i).firstname" to be changable. so if the user wants to search by there last name first name would change to the last name variable. so that i dont need to make a new if statement for each of the options they search by. problem is that when i type "info(i).option (option being a variable set by the user. so if they want to search by first name option would=firstname or by house number option would=homenum) it doesnt read option as a variable. is there any way to do it.

basicly i want it to act something like this should but wont act

Quote:

if search="first name" then
option:=firstname
elsif option="last name" then
option:=lastname
elsif option="home phone" then
option:=homenum
elsif option="cell phone" then
option:=homenum
end if

put "whats the persons ", option
get search2
for decreasing i:friendnum..1 %friendnum is the number of friends the user wants to enter in the phone book
if search2=info(i).option then
infogive (i)
end if
end for
Sponsor
Sponsor
Sponsor
sponsor
rollerdude




PostPosted: Fri Apr 20, 2007 10:19 am   Post subject: Re: help with calling record

well, you have it set up so that option tells you what to look by, when in your for statment,
you told the program to see if "Fred", for example, = "firstname", which always return false. you have to set it up to look in the array for "Fred"

in your record do you have it set up like:

Edited by Clayton: Remember your code/syntax tags children!

Turing:

type phoneRecord:
    record
        first : string
        last : string
        phoneNumber:int%ex. 18005551234 (=1-800-555-1234)
        option : string
    end record


kinda?

what if you dont use an option, but rather, to have something like

Turing:

var option:string

type phonerecord:
    record
        firstname : string
        lastname : string
        number : int
    end record

var phonerecords : phonerecord

%mainline

put"how do you want to search your phone book?"
get option

if option="first" then
    var name:string
    get name
    for i:1..upper(phonerecords)
          if name=phonerecords(i).first then
              %whatever you want it to do
          end if
    end for
elsif option = "last"
    ...


you get the idea


maybe this might help?
ejoman3002




PostPosted: Fri Apr 20, 2007 11:46 am   Post subject: Re: help with calling record

that is what iv done. basically looks like this

Turing:

put"what do u want to do"
put"OPTION:"
put"first name"
put"last name"
put"address"
put"cell number"
put"home number"
put"month of birth"
put"nick name"
get search:*

if search="first name" then
    put" whats the persons first name"
    get search2
    for decreasing i:friendnum..1
        if search2=info(i).firstname then
            infogive(i)  %procedure that outputs all the info on the sertain user
        end if
    end for
elsif search="last name" then
    put" whats the persons last name"
    get search2
    for decreasing i:friendnum..1       
        if search2=info(i).lastname then
            infogive(i)     
        end if 
    end for
elsif search="address" then
    put" whats the persons address"
    get search2
    for decreasing i:friendnum..1       
        if search2=info(i).address then
            infogive (i)     
        end if         
    end for
elsif search="cell number" then
    put" whats the persons cell number"
    get search2
    for decreasing i:friendnum..1       
        if search2=info(i).cellnum then
            infogive (i)     
        end if     
    end for
elsif search="home number" then
    put" whats the persons home number"
    get search2
    for decreasing i:friendnum..1       
        if search2=info(i).homenum then
            infogive (i)         
        end if       
    end for
elsif search="month of birth" then
    put" whats the persons birth month"
    get search2
    for decreasing i:friendnum..1     
        if search2=info(i).bmonth then
            infogive (i)           
        end if       
    end for
elsif search="nick name" then
    put" whats the persons nick name"
    get search2
    for decreasing i:friendnum..1       
        if search2=info(i).nickname then
           infogive (i)
        end if       
    end for
end if

this works but i want a more effiecient way of doing it. something that wont take up so much lines of code. i dont like it this way.
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  [ 3 Posts ]
Jump to:   


Style:  
Search: