Types and sets in Pascal

February 15, 2011 at 10:18:25
Specs: Macintosh
I wanted to know if anybody could help me with sets and types and that sort of things. Actually, I just want the program to read a variable a, which is a character that the users types, and check whether it is a vowel or not. So I wanted to make a set that is composed of 'a','u','i','e','o','y' and just wanted to make an if test to check whether it is in that set. However, as simple as it seems, I didn't managed to do it… Could anybody help please ?

See More: Types and sets in Pascal

Report •

February 15, 2011 at 10:33:15
I think that you are going about things the wrong way. For this problem I would use a "case" statement rather than a special type.

Report •

February 16, 2011 at 03:39:44
I agree with ijack, but if you absolutely want to code a sample using set as type and constants the following is a Pascal program of that kind. Likely unusual since quite cumbersome to handle.

Program vowel;

type letters= set of 'A'..'Z';
const vowels: letters = ['A','E','I','O','U','Y'];
var key: char;

Write ('Enter a char>'); ReadLn (key);

if UpCase(key) in vowels then
  WriteLn ('  You entered a vowel: ', key)
  WriteLn ('  The character you entered is not a vowel: ', key);

Report •

Related Solutions

Ask Question