
-----------------------------------
chibitenshi_03
Wed Feb 11, 2004 9:27 pm

Right justisfy?! Help ASAP
-----------------------------------
var text : int
var maxLength : int :=60
var word : string
var lineLength : int := 0
open : text, "NewText.txt", get
loop
    get : text, skip
    exit when eof (text)
    get : text, word
    if lineLength + length (word) < maxLength then
        put " ", word ..
        lineLength := lineLength + length (word) + 1
    else
        put " "
        put word ..
        lineLength := length (word)
    end if
end loop
put " "
How do i make the words right justisfy instead of left justify???

-----------------------------------
McKenzie
Wed Feb 11, 2004 9:34 pm


-----------------------------------
Should have stayed after school today  :) 

As you know right is a lot harder than left. The problem is you need to insert spaces at the front of each line, but you don't know how many until you have read more than 60 characters. You will need a string variable that you use to keep track of (by concatenating) the words in the sentence. When you can't add any more words output the line then start again. Watch out for:
1. What happens to that last word that did not fit.
2. The last sentance in your data file.

-----------------------------------
Paul
Wed Feb 11, 2004 9:37 pm


-----------------------------------
Wow Mackenzie, you hand out some tough assignments, i hope this is not in grade 10...
Im in grade 10, and the first thing that comes to mind here to me is use locate or put " ":10 or drawtext would be easier.

-----------------------------------
chibitenshi_03
Wed Feb 11, 2004 9:38 pm


-----------------------------------
huh? i'm confused? :?

-----------------------------------
McKenzie
Wed Feb 11, 2004 9:42 pm


-----------------------------------
First Paul, it's not my assignment (we have two CS teachers here at Massey) and this one is straight out of the book. The code you see is also straight out of the book (gr 11).

OK, Chi, how well do you understand the code you posted?

-----------------------------------
Paul
Wed Feb 11, 2004 9:43 pm


-----------------------------------
Mackenzie, would it be alright if say I were doing the assignment and I made the drawtext exactly the same as the output font, and then I counted the number of letters and stuff and then messed around with it so that the coordinate would minus from maxy? and it changes with the length of string so that it would fit perfectly, as in right align. And then Im outta this teacher student conversation.

-----------------------------------
chibitenshi_03
Wed Feb 11, 2004 9:44 pm


-----------------------------------
not that well... :(

-----------------------------------
McKenzie
Wed Feb 11, 2004 9:53 pm


-----------------------------------
The problem, Paul, is knowing where the spaces are. Because you are reading from a file you don't know where to locate until it is too late (short of doing a Pic.New/Pic.Draw manipulation.

Back to the problem
~~~~~~~~~~~~~
Cut your code down to where you understand and add comments to be sure you get it. I suggest starting with:
var text : int
var maxLength : int := 60
var word : string
var lineLength : int := 0
open : text, "NewText.txt", get
loop
    get : text, skip
    exit when eof (text)
    get : text, word
    put word ..

end loop
put " "


-----------------------------------
chibitenshi_03
Wed Feb 11, 2004 10:11 pm


-----------------------------------
umm i don't understand what this line means:
lineLength := lineLength + length (word) + 1
and this one:
lineLength := length (word)
 :?

-----------------------------------
jonos
Wed Feb 11, 2004 10:17 pm


-----------------------------------
that is just setting the linelength variable to something else, in the first case:

linelength (previously), the length of the word, and 1

in the second case, it is initializing lineLength to the length of word

-----------------------------------
McKenzie
Wed Feb 11, 2004 10:21 pm


-----------------------------------
lineLength := lineLength + length (word) + 1 
they are keeping track of how far along the line they are. With each new word they must add on the length of the word plus the length of the space. They need to do this to know when to stop putting them on the same line.

lineLength := length (word) 
When we find that the last word does not fit that word becomes the first in the next line, so the length of that line is the length of the word itself.

-----------------------------------
chibitenshi_03
Wed Feb 11, 2004 10:25 pm


-----------------------------------
ohhhhh i get it now! thanks :D
