plz help me out
plz help me out
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
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
kuull
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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
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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
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!
#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!
Linster: Accessing a string like a character array
>>>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)
That's MID$(string, position, number of characters)
MID$(A$,I,1) is equivalent to A(I,1)
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%
Mida sa loed ? Nagunii aru ei saa
- burger2227
- Veteran
- Posts: 2466
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
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
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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
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...
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...
Ralph, with QuickBASIC 4.5, operating under Windows XP, wiht anHP LaserJet 4L Printer. Bilingual in English/Spanish