Link to home
Start Free TrialLog in
Avatar of aki21
aki21

asked on

Help with Pascal program

I need to write a program that:

a)  Prompts the user to enter a product code.

b)  Enable entry of the product code whilst ensuring that only upper case vowels and digits 1 to 5 are accepted.

c)  Display the code successfully entered.
Avatar of MannSoft
MannSoft

You'll have to write a custom input function using ReadKey.  After calling ReadKey I would use a CASE statement to see what key was pressed.  

Im not sure what you mean in part (B) about the upper case.  If you mean you have to ignore lowercase letters altogether (which would be annoying in a real-world situation), then you dont need to do anything extra.  If you mean you need to bring any lowercase letters to uppercase, then you should use UpCase(ReadKey) instead.

In either case, your CASE statement should check a range of characters, specifically 'A'..'Z', '1'..'5'.

I know I havent given you any code, but that should be all the information you need to write the custom input function.
ASKER CERTIFIED SOLUTION
Avatar of cang24
cang24

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh I didnt see the vowels part, that makes a difference in what I said.

cang24:
We're not really supposed to do homework for other people here.  I see you just registered today so may not have known that, but in the future you should probably just try to help them along, and not do the entire assignment for them.
Avatar of dbrunton
Give them help if they've posted code.

If there's no code ignore them.
Yeah but then you'll have people posting:

program homework;

begin
end.

and going "Ok, I posted some code.  Can you fix it for me?" :-)
Sorry, I'll take tha note
I wrote right??
No problem

This one's a nice simple one and there's no harm done here.   If the questioner can't do this he's not going any further as a programmer.

It's the ones that require an invoice and billing system of 500 lines of code in 24 hours that really annoy you.
Heck that should be eay.  Its when they want full documentation included.

mlmcc
cang24's code should be modified the next way to process special keys. First, if the key code is in set [#1..#31] it should be written to output, nor to function's result. If the key code is equal to #0 you must perform the sequential readkey to remove functional (like F1, F2, arrows, etc) key codes from output stream like it is done by the standart MS-DOS #9 function.

Best regards
Serge
Avatar of aki21

ASKER

Thankyou everyone I have managed to SOLVE the problem.

Program Prodcode;
Uses Crt;
Var
Keycode : String;
Key:char;
Begin
Clrscr;
Write('Enter a product code  :');
Writeln;
Key := ' ';
Repeat
Key := Readkey;
write(Key);
if Key In ['A' , 'E' , 'I' , 'U' ,'O' , '1'..'5'] then
Keycode:= Keycode + Key;
Until Key =#13;
Writeln;
gotoxy(28,5);
writeln('Code is :', Keycode);
Readln;
end.
aki one thing you need to learn...
Make your code easier to read!

Program Prodcode;

Uses Crt;

Var
  Keycode : String;
  Key:char;
Begin
  Clrscr;

  Write('Enter a product code  :');
  Writeln;
  Key := ' ';

  Repeat
    Key := Readkey;
    write(Key);
    if Key In ['A' , 'E' , 'I' , 'U' ,'O' , '1'..'5'] then
      Keycode:= Keycode + Key;
  Until Key =#13;

  Writeln;
  gotoxy(28,5);
  writeln('Code is :', Keycode);
  Readln;
end.
aki21:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
I believe cang24 answered it or at least provided wnough hints on this homework problem to warrant the points.

mlmcc
Yep, I'll agree.  Points to cang24