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

Username:   Password: 
 RegisterRegister   
 Printing to a file problem ... embarssing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Kuntzy




PostPosted: Mon Feb 02, 2004 10:23 pm   Post subject: Printing to a file problem ... embarssing

just look at this code, and when you open up the text file, all of the lines are running continueously after one another? what have i forgotten?


factors.t
 Description:

Download
 Filename:  factors.t
 Filesize:  302 Bytes
 Downloaded:  124 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Kuntzy




PostPosted: Mon Feb 02, 2004 10:24 pm   Post subject: (No subject)

don;t post anything about how stupid i am, i feel stupd enough for even asking this
Paul




PostPosted: Mon Feb 02, 2004 10:27 pm   Post subject: (No subject)

What do you mean? It looks fine to me if your trying to find prime numbers from 2 to 150, though you don't show the prime number factors.
santabruzer




PostPosted: Mon Feb 02, 2004 10:38 pm   Post subject: (No subject)

well .. you just gotta do this or something of the sort :

code:
var fil : int
open : fil, "Factors.txt", put

for i : 2 .. 150
    put : fil, chr (10), "Factors of ", i, ": " ..
    put "Factors of  ", i, ": " ..
    for j : 2 .. i - 1
        if i mod j = 0 then
            put : fil, j, "  " ..
            put j, " " ..
        end if
    end for
    put ""
end for

close (fil)


As you can see..
code:
put : fil, chr (10), "Factors of ", i, ": " ..

is added, and the chr (10) basically is the "enter" in the txt file...
Kuntzy




PostPosted: Tue Feb 03, 2004 8:34 pm   Post subject: (No subject)

yeah, thanx for the help, the code was fine except for writing to the file, i couldn't get the line to skip down on the text file.
Mazer




PostPosted: Wed Feb 04, 2004 2:32 pm   Post subject: (No subject)

Hey Kuntzy,
just replace the
code:

put ""

after your for loop with
code:

put : fil, ""

Or, if you want the output on the screen to be properly formatted, then add the previous line instead of using it to replace that first one.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: