Computer Science Canada

removing gaps

Author:  JR [ Thu Mar 25, 2004 9:19 am ]
Post subject:  removing gaps

here is my program, and whatever i make a gap it counts it as well, how do i skip the gaps so it wont count it?

code:
var line : string
var a : int
var prec : real
var letters : array 1 .. 26 of int
setscreen ("graphics:500;600")
for z : 1 .. 26
    letters (z) := 0
end for
put "Enter your text"
loop
    get line : *
    for i : 1 .. length (line)
        if line (i) not= ' ' then
            letters ((ord ((line (i))) - 96)) := letters ((ord ((line (i))) - 96)) + 1
        end if
    end for
    put " "
    put "letters", "      ", "precentage"
    for i2 : 1 .. 26
        prec := letters (i2) / length (line) * 100
        put ""
        put chr (96 + i2), " : ", letters (i2), "\t", "\t", round (prec), " % " ..
        a := round (prec)
        exit when i2 = 26
    end for

Author:  nate [ Thu Mar 25, 2004 10:01 am ]
Post subject: 

Before the main part of your program put in this code to figure out the length of just the text ignoring the spaces

code:

var length :int

for z : 1..length(line)
         if line(z) not= ' ' then
                 length := length + 1
         end if
end for

So then inseat of using length(line) use the variable length for the length of the characters in the line

Author:  GUI.GetScrollBarWidth : i [ Thu Mar 25, 2004 11:50 am ]
Post subject: 

change your code with this and it should work
code:

var line : string
var a : int
var prec : real
var letters : array 1 .. 26 of int
setscreen ("graphics:500;600")
for z : 1 .. 26
    letters (z) := 0
end for
put "Enter your text"
loop
    get line : *
    for i : 1 .. length (line)
        if line (a) not= ' ' then
            letters ((ord ((line (a))) - 96)) := letters ((ord ((line (i))) - 96)) + 1
        end if
    end for 
    put "letters", "      ", "precentage"
    for i2 : 1 .. 26
        prec := letters (i2) / length (line) * 100
        put ""
        put chr (96 +y21), " : ", letters (i2), "\t", "\t", round (prec), " % " ..
        a := round (prec)
        exit when i2 = 26
    end for

Author:  nate [ Thu Mar 25, 2004 5:45 pm ]
Post subject: 

When you help some1 make sure your code actually works! Did you even test it. IT doesn't even run!

Author:  JR [ Tue Mar 30, 2004 9:27 am ]
Post subject: 

so how do i close those gaps?

Author:  nate [ Tue Mar 30, 2004 6:57 pm ]
Post subject: 

What do u mean by close the gaps? be more specific

*just for clarification by gaps you mean spaces?

Author:  JR [ Tue Mar 30, 2004 7:09 pm ]
Post subject: 

ok lets say that u type aaa aaa in the program, the program counted the space and made it eaqual to 86% instead of 100 a's. how do i make the program not calculate this space?

Author:  jonos [ Tue Mar 30, 2004 7:59 pm ]
Post subject: 

for counter : 1.. length(sentence)
if sentence(counter) not= " " then
letterCount += 1
end if
end for

Author:  nate [ Tue Mar 30, 2004 9:07 pm ]
Post subject: 

hahaha, nice spam jonos but just look up the page at like the exact same code! lol, w.e

Basically JR you need to read the last post by me or jonos. The thing is you don't take spaces away you just ignore them. This board isn't here 2 do ur work just help you at it.

Good Luck


: