Board index » delphi » Simple Pascal Problem

Simple Pascal Problem

Heya Guys,

Was hoping I could get some input on my problem for class.

I have to write a program that returns a check character from an integer
value.

It is suppose to simulate CreditCard Verification methods, but the class
problem calls for a 10 digit number.

Here is the program in 'PseudoCode'  (or a light English Version)

    Get a 10 digit number from the user
    Break the 10 digit number into 5 two number pairs.
    Add the 5 pairs of numbers.
    Take Sum MOD 26
    Return Check Character as a letter in position of alphabet.  Assuming A
= 0

OK - Getting the 10 digit number is easy, so is adding it.  The Sum MOD 26
is no problem,

But what I need to figure out is the easiest way to break it into pairs. .
.is it some form of division by 100?

Also I think I can write the end code like this. . .
   begin
       CheckChr := chr (PreviousResult + ord('a'))
   end;

is this correct?   Any Ideas on breaking the 10 digit number up.

Thanks in Advance guys!

Mike

 

Re:Simple Pascal Problem


Hello,
ever tried out something like this:
for i:= 5 downto 1 do
begin
  check[ i ] := value mod 100;
  value := value div 100;
end;

It is just an idea. I don't guarantee that this works

Re:Simple Pascal Problem


Ok. . .Good. . . got me thinking.. . . .

Now I have to add an assignment string so that I can Output 5 values because
I have to add them later to get the checksum.

THANKS!

Mike

Quote
"Dietrich Czapp" <nc-czap...@netcologne.de> wrote in message

news:3BACE5E2.7AC4A6A1@netcologne.de...
Quote
> Hello,
> ever tried out something like this:
> for i:= 5 downto 1 do
> begin
>   check[ i ] := value mod 100;
>   value := value div 100;
> end;

> It is just an idea. I don't guarantee that this works

Re:Simple Pascal Problem


Quote
Beginning Programmer wrote:

> I have to write a program that returns a check character from an
> integer value.  It is suppose to simulate CreditCard Verification
> methods, but the class problem calls for a 10 digit number.

> Here is the program in 'PseudoCode'  (or a light English Version)

>     Get a 10 digit number from the user
>     Break the 10 digit number into 5 two number pairs.
>     Add the 5 pairs of numbers.
>     Take Sum MOD 26
>     Return Check Character as a letter in position of alphabet.
>         Assuming A = 0

> OK - Getting the 10 digit number is easy, so is adding it.  The Sum MOD 26
> is no problem,

> But what I need to figure out is the easiest way to break it into pairs. .
> .is it some form of division by 100?

CONST
  maxindex  = 26;

TYPE
  chrindex  = 0..maxindex;  (* zero for invalid *)

FUNCTION chkchrindex(n : integer) : chrindex;

  VAR
    chksum  : integer;

  BEGIN (* chkchrindex *)
  chksum := 0;
  WHILE n > 0 DO BEGIN
    chksum := chksum + (n MOD 100);
    n := n DIV 100;
    END;
  chkchrindex := (chksum MOD maxindex) + 1;
  END; (* chkchrindex *)

Not a good chkdigit algorithm.

--
Chuck F (cbfalco...@yahoo.com) (cbfalco...@XXXXworldnet.att.net)
   (Remove "XXXX" from reply address. yahoo works unmodified)
   mailto:u...@ftc.gov  (for spambots to harvest)

Re:Simple Pascal Problem


I get an "invalid qualifier" error when compiling this

Quote
>   check[ i ] := value mod 100;

In general. . .when using a variable that changes value according to the
number of the loop. . . how do you define it? I tried a simple

VAR   check : integer;

assignment but that didn't seem to work and I haven't covered this yet in my
studies!

Thanks SO Much in Advance for your input

Michael

Re:Simple Pascal Problem


Here is the code I came up with.  It should meet the following objectives:

Computes a Check Character according to the following rules:
   Start with 10 digit number from user
   Add the 5 pairs it contains
   Take The Sum MOD 26
   Return a Check Character as a letter in that position of the Alphabet
with A = 0.

Thanks For the Help - Michael

*************************************************************

program SecondProgram (input,output);

var UserNumber : longint; {longint because the # is 10 digit Number}
    CheckNumb : integer;
    CheckChar : char;

CONST
   maxindex = 26;

FUNCTION chkchrindex (UserNumber : longint) : integer;

VAR NumberTotal : integer;

begin
     NumberTotal := 0;
     while UserNumber > 0 do
        begin
          NumberTotal := NumberTotal + (UserNumber MOD 100);
          UserNumber := UserNumber DIV 100;
          writeln ('Here is the output', ' NumberTotal -  ', NumberTotal,'
UserNumber -   ', UserNumber);
        end;
     chkchrindex := (NumberTotal MOD maxindex); {This is the Sum MOD 26
line }
end;

begin
     write ('Please enter a ten digit number');
     readln (UserNumber);
     CheckChar := chr(chkchrindex(UserNumber)+ ord('a'));
   { CheckNumb := ord(CheckChar) - ord('a'); { This is how I tested the
number generator }
     writeln ('The Check Character assuming A = 0 is','  ',CheckChar,' . ');
end.

Other Threads