New To Pascal please help - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

New To Pascal please help

TeebooTeeboo Posts: 1Member
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

Comments

  • ManningManning Posts: 1,621Member
    : 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:

    [code]
    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;
    [/code]

    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 :)
  • Phat NatPhat Nat Posts: 757Member
    : 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
    :

    [code]
    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 "',
    Number," on the phone pad.');
    End.
    [/code]

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

    Phat Nat
Sign In or Register to comment.