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

Username:   Password: 
 RegisterRegister   
 Writing in Turing with Arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
XeroX




PostPosted: Sun May 21, 2006 1:39 pm   Post subject: Writing in Turing with Arrays

Is it at all possible to write to a file with an array, as this leads to the error "Put stream number must be int type"

here is my code:
code:
%%%%%%%%%%%%%%%%%%%%%%
%Variable Declaration%
%%%%%%%%%%%%%%%%%%%%%%
var manynumbers : int
var temp1 : string
var temp2 : string
var stremout : int %a var that is an int is needed to open a file

%%%%%%%%%%%%%%%%%%%%%%
%Main Program%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%
put "Welcome to the PhoneBook"
put "We will sort your numbers alphabetically and save them to a text file"

put "How many numbers would you like to enter?"
get manynumbers

var phonenumber : array 1 .. manynumbers of string
var phonename : array 1 .. manynumbers of string

for r : 1 .. manynumbers
    put "Please enter the name"
    get phonename (r)
    cls

    put "Please enter the number"
    put skip
    get phonenumber (r)
    cls
end for

%sorting the numbers by alpheabetical order

for i : 1 .. manynumbers
    for decreasing j : manynumbers .. i + 1
        if phonename (j - 1) > phonename (j) then

            temp1 := phonenumber (j - 1)
            temp2 := phonename (j - 1)

            phonenumber (j - 1) := phonenumber (j)
            phonename (j - 1) := phonename (j)

            phonenumber (j) := temp1
            phonename (j) := temp2
        end if
    end for
end for

for q : 1 .. manynumbers
    put phonename (q), "'s number is: ", phonenumber (q)
end for

open : stremout, "phonebook.txt", put %open a connection to send data

for p:1..manynumbers
    put : phonename(p) , "'s number is: ", phonenumber (p)
    exit when p=manynumbers
end for

close : stremout
Sponsor
Sponsor
Sponsor
sponsor
XeroX




PostPosted: Sun May 21, 2006 1:41 pm   Post subject: (No subject)

please ignore the exit when p=manynumbers

thanks.
jamonathin




PostPosted: Sun May 21, 2006 2:29 pm   Post subject: (No subject)

The first part must be int (i.e something that represents your file)

code:

for p : 1 .. manynumbers
    put : stremout, "'s number is: ", phonenumber (p)
    exit when p = manynumbers
end for
XeroX




PostPosted: Sun May 21, 2006 2:58 pm   Post subject: (No subject)

Thats great, Thanks!
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  [ 4 Posts ]
Jump to:   


Style:  
Search: