Pascal

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

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
New To Pascal please help Posted by Teeboo on 4 Nov 2003 at 8:23 PM
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
Report
Re: New To Pascal please help Posted by Manning on 5 Nov 2003 at 2:55 PM
: 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 :)
Report
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 "',
              Number," on the phone pad.');
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
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.