Types and sets in Pascal

February 15, 2011 at 10:18:25
Specs: Macintosh
Hi,
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 •


#1
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 •

#2
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;

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

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


Report •

Related Solutions


Ask Question