## Pascal

Moderators: None (Apply to moderate this forum)
Number of posts: 14007

This Forum Only

I am a freshman in high school and new to pascal. for school we have to make a program that reads what character on the phone pad a user enters and writes what that character would be as a number, like B would be 1, so on...........can someone plz help im no good with case statements
: I am a freshman in high school and new to pascal. for school we have to make a program that reads what character on the phone pad a user enters and writes what that character would be as a number, like B would be 1, so on...........can someone plz help im no good with case statements

Here's a somewhat similar example that you should be able to adapt:

```Ch := ReadKey;
case UpCase(Ch) of
// Matches any characters between 0 and 9
'0'..'9': WriteLn('Numeral');

// Matches only the characters supplied
'A', 'E', 'I', 'O', 'U': WriteLn('Vowel');

// Matches anything that isn't matched above
else
WriteLn('Consonant');
end;
```

BTW, unless you live in another country where your phones are different, the 1 button doesn't have any letters associated with it. So the B actually corresponds to the 2 button. Might want to double check that before you write any code :)
Re: New To Pascal please help Posted by Phat Nat on 6 Nov 2003 at 1:30 AM
: I am a freshman in high school and new to pascal. for school we have to make a program that reads what character on the phone pad a user enters and writes what that character would be as a number, like B would be 1, so on...........can someone plz help im no good with case statements
:

```VAR
Letter : Char;
Number : ShortInt;
Begin
Letter := UpCase(Readkey);   { Turn the letter to upper case }
Case Letter Of
'A'..'C' : Number := 1;
(* Add the middle ones in here *)
'M'..'O' : Number := 5;
'P',
'R'..'S' : Number := 6;   { Remember, no letter "Q" }
(* and add the rest in here *)
ELSE Number := -1;        { If they enter "Q" or "Z", return -1 }
END;
WriteLn('The Letter "',Letter,'" corresponds to the number "',
End.
```

This is a basic idea. Should be able to fill in the rest.

Phat Nat

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic