New To Pascal please help

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

  • : 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 :)
  • : 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.

Howdy, Stranger!

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

Categories