Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help with Pascal program

Posted on 2003-03-26
16
Medium Priority
?
207 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:aki21
  • 4
  • 3
  • 2
  • +5
15 Comments
 
LVL 6

Expert Comment

by:MannSoft
ID: 8210491
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.
0
 

Accepted Solution

by:
cang24 earned 100 total points
ID: 8211814
That's easy to do.

Function MyRead:string;
  key:char;
  cad:string;
  begin
  ...
  key:=chr(0);
  while key<>chr(13) do
    begin
      key:=readkey;  {key:=upcase(readkey);}
      if key in['A','E','I','O','U','1'..'5'] then
        begin
          concat(cad,key)
          write(key);
        end
      else write(^g);
    end;
  MyRead:=cad;
end;

This function accept AEIOU12345, but there is no "backspace" function so U need implement it. If you use the commented sentence you'll accept AEIOUaeiou12345 but in lower case ->>>UPPER CASE
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 8212268
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.
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
LVL 50

Expert Comment

by:dbrunton
ID: 8212597
Give them help if they've posted code.

If there's no code ignore them.
0
 
LVL 6

Expert Comment

by:MannSoft
ID: 8212625
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?" :-)
0
 

Expert Comment

by:cang24
ID: 8212671
Sorry, I'll take tha note
I wrote right??
0
 
LVL 50

Expert Comment

by:dbrunton
ID: 8212741
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.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8214453
Heck that should be eay.  Its when they want full documentation included.

mlmcc
0
 
LVL 50

Expert Comment

by:dbrunton
ID: 8215488
:-)
0
 
LVL 5

Expert Comment

by:msa2003
ID: 8252885
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
0
 

Author Comment

by:aki21
ID: 8256710
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.
0
 
LVL 6

Expert Comment

by:PoeticAudio
ID: 8291536
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.
0
 

Expert Comment

by:CleanupPing
ID: 9314355
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.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 9325724
I believe cang24 answered it or at least provided wnough hints on this homework problem to warrant the points.

mlmcc
0
 
LVL 50

Expert Comment

by:dbrunton
ID: 9326670
Yep, I'll agree.  Points to cang24
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This applies to Dell but may also apply to other manufacturers as well. We ran across a few machines that just dropped recently it trust relationship with the server. After doing the basic removing and joining the domain again, it changed to No logo…
In my humble opinion (IMHO), TouchDown from Symantec is the best in class for this type of application, but Symantec has end-of-lifed it and although one can keep using it, it will no longer be supported or upgraded.  Time to look for alternatives t…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question