Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with vowels
#1
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:
ww.GameFusionX.com/forums
Reply
#2
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)
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
many thanks
ww.GameFusionX.com/forums
Reply
#4
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
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#5
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
Reply
#6
I said simpler, not shorter. This way he doesn't have to know what MID$() is.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#7
This is noob at its best, but how do i get it to work with capitals?
ww.GameFusionX.com/forums
Reply
#8
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
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#9
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$
Reply
#10
Yea good point. Zack, since when was "Y" a vowel?

And yes, I admit you were right about the simpler thing. =P :lol:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)