Page 1 of 1

plz help me out

Posted: Thu Jun 26, 2008 12:43 pm
by kuul
write a program that takes a multi-word string from the keyboard amd counts how many times each letter shos up.
the count should be case insensitve. meaning "A" is the same as "a"
sample input
enter a string: i love to Sing and Dance

sample out put:
a=2
c=1
d=2
e=2
g=1
i=2
l=1
n=3
o=2
s=1
t=1
v=1

Posted: Thu Jun 26, 2008 1:09 pm
by burger2227
Sounds like homework to me!

We don't do homework, but here are some hints.

1) Place the string into a variable$ and LCASE$ or UCASE$ it.

2) Use a loop to get each letter of the string using MID$.

3) USE the ASCII codes to determine the count. Look up the codes and the ASC function. You will need IF or CASE statements for the codes returned. You could also place the counts into an Array if you know how.

You probably have been taught this stuff already. You would be cheating if I said more!

Ted

Posted: Sat Jun 28, 2008 12:53 am
by linster
Actually with C it's very easy (I've been learning alot of languages while not around). Basically you do something similar to this:

#include <stdio>;
main (str[128]) {

int position;
int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, x, y, z;
position = 1;
while (position <= 128) {
if (str[position] != ("a" || "b || "c" || "d" || "e" || "f" || "g" || "h" || "i" || "j" || "k" || "l" || "m" || "n" || "o" || "p" || "q" || "r" || "s" || "t" || "u" || "v" || "w" || "x" || "y" || "z")) {
position++;
}
if (str[position] == "a" ) { a++; }
if (str[position] == "b" ) { b++; }
if (str[position] == "c" ) { c++; }
if (str[position] == "d" ) { d++; }
if (str[position] == "e" ) { e++; }
if (str[position] == "f" ) { f++; }
if (str[position] == "g" ) { g++; }
if (str[position] == "h" ) { h++; }
if (str[position] == "i" ) { i++; }
if (str[position] == "j" ) { j++; }
if (str[position] == "k" ) { k++; }
if (str[position] == "l" ) { l++; }
if (str[position] == "m" ) { m++; }
if (str[position] == "n" ) { n++; }
if (str[position] == "o" ) { o++; }
if (str[position] == "p" ) { p++; }
if (str[position] == "q" ) { q++; }
if (str[position] == "r" ) { r++; }
if (str[position] == "s" ) { s++; }
if (str[position] == "t" ) { t++; }
if (str[position] == "u" ) { u++; }
if (str[position] == "v" ) { v++; }
if (str[position] == "w" ) { w++; }
if (str[position] == "x" ) { x++; }
if (str[position] == "y" ) { y++; }
if (str[position] == "z" ) { z++; }
}

}




Ok, now other members of the board are going to yell at me for this not being in basic, or for solving someone's homework, but I actually provided a subtle hint, and a probable (but very bloated) solution.

TO Kuul:

What function in basic allows you to access part of a string just like it was in a character array?

What is wrong with my solution, did I forget to validate some input (does it have to do anything with case?)

How might I go about fixing that? (Think $CHR)

Would it be dangerous if someone entered a sentence with more than 128 characters? Why?

Please reply! :)

Posted: Sat Jun 28, 2008 10:22 am
by TmEE
C code makes less sense to me than someone else's asm code.

anyway, I wrote something that will do what's required and its 9 lines of QB code.

I had 2x FOR loops, I used UCASE$, MID$, CHR$, ASC and LEN. And all the results are printed on screen.

Posted: Sat Jun 28, 2008 2:51 pm
by sid6.7
kuul


people will be glad to help if you actually show the code you are working on and having trouble with and not just asking us if we will do your homework for you. its not the way we do things around here.

moderator

Linster: Accessing a string like a character array

Posted: Tue Jul 01, 2008 7:08 am
by markm
>>>What function in basic allows you to access part of a string just like it was in a character array?

That's MID$(string, position, number of characters)

MID$(A$,I,1) is equivalent to A(I,1)

Posted: Sun Jul 27, 2008 6:28 am
by TmEE
Now my code is not wasted...

Code: Select all

a$ = "one two three testing testing"
a$ = ucase$(a$)
for j% = 0 to 255
c% = 0
for i% = 1 to len(a$)
if j% = asc(mid$(a$, i%, 1)) then c% = c% + 1
next i%
print chr$(j%) + "="; c%,
nexi j%

Posted: Sun Jul 27, 2008 2:25 pm
by Ralph
Kuul, where are you? We expect you to post again, either thanking those who helped you or asking help on some part that you don;t undrstand or can't get to work. Please respond.

Posted: Sun Jul 27, 2008 3:18 pm
by burger2227
That's what you get, when somebody just writes all of the code for you.

Especially if it's wrong! Why would a CHEATER say thanks anyway? Also if the code don't work, they just cheat somewhere else..........

Ted

Posted: Tue Jul 29, 2008 11:01 am
by Ralph
burger2227:

It's sad to feel that some, or most, of the new and young posters here. The way I try tomake sure I'm addressing an honestly interested young person is to ask, first, what their goal might be. If I get that answered, I offer to help review thiere code, etc. That is, I try to base my help on what they do, on their iniciative. I can keep that up, as long as I keep gitting positive indications that they are interested. As soon as they stop responding, so do I...