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

Username:   Password: 
 RegisterRegister   
 removing gaps
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JR




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
nate




PostPosted: Thu Mar 25, 2004 10:01 am   Post subject: (No 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
GUI.GetScrollBarWidth : i




PostPosted: Thu Mar 25, 2004 11:50 am   Post subject: (No 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
nate




PostPosted: Thu Mar 25, 2004 5:45 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 30, 2004 9:27 am   Post subject: (No subject)

so how do i close those gaps?
nate




PostPosted: Tue Mar 30, 2004 6:57 pm   Post subject: (No subject)

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

*just for clarification by gaps you mean spaces?
JR




PostPosted: Tue Mar 30, 2004 7:09 pm   Post subject: (No 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?
jonos




PostPosted: Tue Mar 30, 2004 7:59 pm   Post subject: (No subject)

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




PostPosted: Tue Mar 30, 2004 9:07 pm   Post subject: (No 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
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  [ 9 Posts ]
Jump to:   


Style:  
Search: