carlkane@hotmail.com
Guest
|
Post by carlkane@hotmail.com on Apr 18, 2002 23:24:03 GMT
I am in a bit of trouble with the program I am trying to do at the moment and I just cannot get it to work and I was wondering whether you could help me with it.
I need to write a program in Q-Basic to check a sentence against eact letter of the alphabet and report back the number of times each letter occurs in the sentence.
eg A B C D EE 1 1 1 1 2
This shows that "A, B, C, D" all occur once and "EE" occurs twice.
I would be very grateful if you could shed any light on this for me.
Thank you
Carl
|
|
pebe
Junior Member
Posts: 39
|
Post by pebe on Apr 20, 2002 6:37:21 GMT
Here's a program that will deal with single letters. You may be able to modify it for the double letters you want.
t$ = "At the time I was waiting for the bus to come" DATA 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
CLS PRINT t$ PRINT FOR n% = 1 TO 26 READ test$ y% = 0 FOR in% = 1 TO LEN(t$) IF UCASE$(MID$(t$, in%, 1)) = test$ THEN y% = y% + 1 NEXT PRINT , test$; " ="; y%; NEXT
|
|
webmaster@bonafidebasic.zzn.co
Guest
|
Post by webmaster@bonafidebasic.zzn.co on Apr 24, 2002 16:43:15 GMT
Excuse me for butting in, but you didn't declare test$. Shouldn't it be, then:
t$ = "At the time I was waiting for the bus to come" DATA 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 CLS PRINT t$ PRINT FOR n% = 1 TO 26 READ test$ y% = 0 FOR in% = 1 TO LEN(t$) IF UCASE$(MID$(t$, in%, 1)) = test$ THEN y% = y% + 1 NEXT PRINT , test$; " ="; y%; NEXT
Sorry if I'm wrong.
|
|
webmaster@bonafidebasic.zzn.co
Guest
|
Post by webmaster@bonafidebasic.zzn.co on Apr 24, 2002 16:45:10 GMT
Dangit. I messed up. What I meant was, replace the test$ with t$.
|
|
pebe
Junior Member
Posts: 39
|
Post by pebe on Apr 24, 2002 18:57:46 GMT
Bona Fide, I'm not sure what you mean. t$ is the sentence being tested. test$ is each letter of the alphabet, read in turn from DATA, to see how many times it occured in the sentence. PRINT t$ was so you could see it on the screen for comparison with the printed results
|
|
pebe
Junior Member
Posts: 39
|
Post by pebe on Apr 24, 2002 19:00:37 GMT
I don't know what the is, it's not part of the mail.
|
|
|
Post by fly@aol.com on May 7, 2002 5:14:54 GMT
I think better would be:
dim alpha[26] 'set alpha array for x = 1 to 26: alpha[26]=0 : next x 'zero array
line$ = "to be or not to be" 'get line line$=lcase$(line$) 'set to lower case length = len(line$) 'get line length
for x = 1 to length 'for length of line value = asc(mid$(line$,1,1))-96 'get 1-26 (a-z) alpha[value] = alpha[value] + 1 'increment array next x
|
|
pebe
Junior Member
Posts: 39
|
Post by pebe on May 7, 2002 18:08:54 GMT
'Better', fly? Well different anyway!
Your prog won't work though.
Your 2nd line should be alpha(x)=0 to clear all the array.
Your line: - value = asc(mid$(line$,1,1))-96 'get 1-26 (a-z) gets the same char each time. It should be value = asc(mid$(line$,x,1))-96 'get 1-26 (a-z) to read each char in turn. You are taking the ASC of each char and subtracting 96. But a space [ASC (" ")] = 32, so that gives -64 which is outside the array limits.
And you still have to print the array.
|
|
pebe
Junior Member
Posts: 39
|
Post by pebe on May 7, 2002 18:10:28 GMT
'Better', fly? Well different anyway!
Your prog won't work though.
Your 2nd line should be alpha(x)=0 to clear all the array.
Your line: - value = asc(mid$(line$,1,1))-96 'get 1-26 (a-z) gets the same char each time. It should be value = asc(mid$(line$,x,1))-96 'get 1-26 (a-z) to read each char in turn. You are taking the ASC of each char and subtracting 96. But a space [ASC (" ")] = 32, so that gives -64 which is outside the array limits.
And you still have to print the array.
|
|
|
Post by piegopher on May 10, 2002 3:33:26 GMT
What exactly is dim and why do you have to use it? I've never used it before...
|
|
pebe
Junior Member
Posts: 39
|
Post by pebe on May 10, 2002 6:33:34 GMT
If you want to use a variable you dont need to declare it in QB, before you use it.
But if you use an array, and dont declare it, it is given a default of 20 (you can store 20 items). If you need to store 26 items as in this case, you need to state how many items you want to store, like
DIM thearray(26)
|
|
yusra_i@hotmail.com
Guest
|
Post by yusra_i@hotmail.com on May 14, 2002 17:11:05 GMT
name =alia
I need to write a program in Q-Basic to check a sentence against eact letter of the alphabet and report back the number of times each letter occurs in the sentence.
i have the output of qbasic and i want the input plz can u help me in this enter first value:? enter second value:? **************** *press 1 for addition* *press 2 for subtraction* *press 3 for multiplication* ********************* 10+5+15 end of program end
|
|
yusra_i@hotmail.com
Guest
|
Post by yusra_i@hotmail.com on May 15, 2002 16:37:32 GMT
i need ur help i have the out put i need the input,, the out put is enter first value enter second value *************** press 1 for addition press 2 for subtraction press 3 for multiplication ******************* 10+5=15 10-5=5 10*5=50 do u want to continue (press 1 for yes and press 2 for no) end of program end plz help me and i want the answer by 15-5-02
|
|
|
Post by piegopher on May 15, 2002 22:32:44 GMT
Erm... if what you're asking for is a program that will do that...
1 CLS INPUT "What is the first value"; a INPUT "What is the second value"; b CLS PRINT "Press 1 for Addition" PRINT "Press 2 for Subtraction" PRINT "Press 3 for Multiplication" c = 0 DO k$ = INKEY$ IF k$ = "1" THEN c = 1 IF k$ = "2" THEN c = 2 IF k$ = "3" THEN c = 3 LOOP WHILE c = 0 CLS IF c = 1 THEN PRINT a; "+"; b; "="; a + b IF c = 2 THEN PRINT a; "-"; b; "="; a - b IF c = 3 THEN PRINT a; "x"; b; "="; a * b 'you can write the previous 3 lines like this: 'if c=1 then print a"+"b"="a+b 'and it will do the rest for you PRINT "" PRINT "Press 1 to continue" DO k$ = INKEY$ IF k$ = "1" then goto 1 LOOP WHILE k$ = "" END
Or if you don't want to type it out, copy and paste it to a .txt file then rename it to .bas and it should work
|
|
yusra_i@hotmail.com
Guest
|
Post by yusra_i@hotmail.com on May 18, 2002 17:01:50 GMT
[i need ur help in designing the other program too plz help me i have the out put i need the input first play enter any no from o to 100 second player it is an even no enter any no from 0 to 100 you have just five chances enter no:9 u have 4 chances left enter no;2 you have won the game end of program end i want the answer by 18th may 2002 plz help me i will be really obliged
|
|