Rohit Lohala
Rohit Lohala

Reputation: 1

How to know if the entered letter is a vowel or a consonant

CLS
INPUT "enter any letter"; a$
b$ = UCASE$(a$)
SELECT CASE b$
    CASE "a", "e", "i", "o", "u"
END SELECT
IF c$ = b$ THEN
    PRINT "Vowel"
ELSE
    PRINT "consonant"
END IF
END

Upvotes: 0

Views: 784

Answers (2)

Sep Roland
Sep Roland

Reputation: 39306

You can use the INSTR function to find out if the inputted character is in the list of vowels:

CLS
INPUT "enter any letter"; a$
IF INSTR("AEIOUaeiou", a$) THEN
    PRINT "Vowel"
ELSE
    PRINT "Consonant"
END IF
END

Not better but feasible is using `UCASE$':

CLS
INPUT "enter any letter"; a$
a$ = UCASE$(a$)
IF INSTR("AEIOU", a$) THEN
    PRINT "Vowel"
ELSE
    PRINT "Consonant"
END IF
END

Upvotes: 2

Mark H
Mark H

Reputation: 4451

If you're going to compare with lowercase letters, be sure to use LCASE$ instead of UCASE$

CLS
INPUT "enter any letter"; a$
b$ = LCASE$(a$)
SELECT CASE b$
  CASE "a", "e", "i", "o", "u"
    PRINT "Vowel"
  CASE ELSE
    PRINT "consonant"
END SELECT

Upvotes: 2

Related Questions