Computer Science Canada

Printing to a file problem ... embarssing

Author:  Kuntzy [ 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?

Author:  Kuntzy [ Mon Feb 02, 2004 10:24 pm ]
Post subject: 

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

Author:  Paul [ Mon Feb 02, 2004 10:27 pm ]
Post 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.

Author:  santabruzer [ Mon Feb 02, 2004 10:38 pm ]
Post 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...

Author:  Kuntzy [ Tue Feb 03, 2004 8:34 pm ]
Post 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.

Author:  Mazer [ Wed Feb 04, 2004 2:32 pm ]
Post 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.


: