?
Solved

Help with Pascal program

Posted on 2003-03-26
16
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +5
16 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
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

 
LVL 49

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 49

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 49

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 49

Expert Comment

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

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introducing Priority Question, our latest feature.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 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