Qbasicnews.com

Full Version: Help with vowels
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Im making a program, in which you have 3 options. Create a file, FInd how many vowels, and quit. What it does is creates a file which the user gets to say how many words are in it, and how many vowels are in the words.

Example


1.Create a file
2.Count the Vowels
3.Quit


Pick 1

How many words would you like to put.

3
-car
-bat
-animal

1.Create a file
2.Count the Vowels
3.Quit

Pick 2

There are 5 vowels in this file.

So far all i cant get is the vowel portion, here is what code i have.




C: CLS



PRINT "Vowel program"
PRINT "----------------------------------------"
PRINT "----------------------------------------"


PRINT "1.Create a file."
PRINT "2.Count The Vowels."
PRINT "3.Quit"


INPUT "choose"; x
IF x <> 1 AND x <> 2 AND x <> 3 THEN GOTO C
IF x = 1 THEN GOTO line1
IF x = 2 THEN GOTO line2
IF x = 3 THEN END


CLOSE #1

line1:

INPUT "how many words do you want to enter"; a
OPEN "H:APR30R.txt" FOR OUTPUT AS #2
FOR i = 1 TO a: CLS
INPUT "Enter a word"; n$
WRITE #2, n$
NEXT i
CLOSE #2


line2:
You'll have to look at every letter and check if it's a e i o u

I recomend MID$


Code:
'open file
DO
LINE INPUT #1, a$
FOR i = 1 TO LEN(a$)
b$ = MID$(a$,i,1)
IF b$ = "a" or b$ = "e"or b$ = "i" or b$ = "o" or b$ = "u" THEN
vowelcount = vowelcount + 1
END IF
NEXT i
LOOP UNTIL EOF(1)
PRINT vowelcount

(untested but should work)
many thanks
WT: it's simpler just to read each character in BINARY file mode, and check if it's A, E, I, O, U, or Y.
Code:
DIM Byte AS STRING * 1
OPEN Filename$ FOR BINARY AS #1
DO UNTIL EOF(1)
    GET #1,,Byte
    IF Byte="A" OR Byte="E" OR Byte="I" OR Byte="O" OR Byte="U" OR Byte="Y"  THEN
        VowelCount%=VowelCount% + 1
    END IF
LOOP
CLOSE #1
Thats true Zack, but if you look at WTs code, it is actually exactly the same size as yours, if you were to include the displaying of the vowel count Wink
I said simpler, not shorter. This way he doesn't have to know what MID$() is.
This is noob at its best, but how do i get it to work with capitals?
Use the LCASE$() function to convert a string to lower case.
Code:
DIM Byte AS STRING * 1
OPEN Filename$ FOR BINARY AS #1
DO UNTIL EOF(1)
    GET #1,,Byte
    Byte=LCASE$(Byte)
    IF Byte="a" OR Byte="e" OR Byte="i" OR Byte="o" OR Byte="u" OR Byte="y"  THEN
        VowelCount%=VowelCount% + 1
    END IF
LOOP
CLOSE #1
I think the easy way, (without having to change your program if you, for example decided that "y" isn't a vowel) would be something like this:

Code:
filename$ = "text.txt"
DIM filechar AS STRING * 1
CONST vowels = "aEiOuY"
vowelcounter% = 0
OPEN filename$ FOR BINARY AS #1
DO
  GET 1, , filechar
  IF INSTR(LCASE$(vowels), LCASE$(filechar)) THEN vowelcounter% = vowelcounter% + 1
LOOP WHILE NOT EOF(1)
PRINT "there were"; vowelcounter%; "vowels in "; filename$
Yea good point. Zack, since when was "Y" a vowel?

And yes, I admit you were right about the simpler thing. =P :lol:
Pages: 1 2 3