'===========================================================================
' Subject: # of Words, Vowels, Consonants     Date: 06-14-03 (  :  )       
'  Author: Fred Buffington                    Code: Qbasic, QB, PDS        
'  Origin: oasys@sbcglobal.net              Packet: TEXT.ABC
'===========================================================================
'======================================================================= ===== 
'Subject:Find words, vowels, consonants in a sentence         DATE:03/18/2003 
'        a teaching tool. 
'Author: Buff oasys@sbcglobal.net                             CODE:QB,PB 
'Origin: oasys@sbcglobal.net                                PACKET:QB.ABC 
'======================================================================= ===== 
'Find the number of words, vowels, and consonants in a sentence 
  DIM words$(50) 'just in case it's more than 10 
 
'------------------------ 
'User input of a sentence 
'------------------------ 
  LINE INPUT "Enter Sentence ", sentence$ 
  Start.position% = 0: last.position% = 0 
'---------------------------------- 
'get the first occurance of a space 
'---------------------------------- 
  sentence$ = RTRIM$(sentence$) 'remove any trailing space 
  L% = INSTR(sentence$, " ") 'look for a space 
  WHILE L% > 0 
    Word.Count% = Word.Count% + 1 
    words$(Word.Count%) = MID$(sentence$, last.position% + 1, L% - 1 - last.position%) 
    last.position% = L% 
    L% = INSTR(last.position% + 1, sentence$, " ") 'look for next space 
  WEND 
'-------------------------------- 
'since L%=0 at the end, get last 
'word from the sentence 
'-------------------------------- 
  IF sentence$ <> "" THEN 
     Word.Count% = Word.Count% + 1 
     words$(Word.Count%) = MID$(sentence$, last.position% + 1, LEN(sentence$) - last.position%) 
  END IF 
  FOR k& = 1 TO Word.Count% 
     FOR x& = 1 TO LEN(words$(k&)) 
        LTR$ = MID$(UCASE$(words$(k&)), x&, 1) 
        SELECT CASE LTR$ 
           CASE "A", "E", "I", "O", "U" 
             Vowels& = Vowels& + 1 
           CASE ELSE 
             Consonants& = Consonants& + 1 
        END SELECT 
     NEXT 
  NEXT 
'-------------------------- 
'print out the results 
'-------------------------- 
  PRINT sentence$ 
  PRINT "has "; LTRIM$(STR$(Word.Count%)); " words" 
  PRINT "    "; LTRIM$(STR$(Vowels&)); " Vowels" 
  PRINT "and "; LTRIM$(STR$(Consonants&)); " consonants" 
  END 'change to system to exit to prompt after running 
 
