Home > Mobile >  Recognize a four character combination and identify where to put them
Recognize a four character combination and identify where to put them

Time:02-02

The first four characters will determine if the card is credit or debit. If it's AABB', 'IT22', '1234', 'AAAA', 'ABAB', 'BSIT', 'STB0', '0000' then it's credit. Else it's a debit. Then, if the second four characters are '3133' the transaction will not proceed. If 9876-1245-A012-AERG was used. It will show DEBIT as it should. But when AABB-1245-A012-EEEE was used, it still shows DEBIT, when it should've been CREDIT because of its first four characters.

Is there an error with my input? Where am I doing it wrong?

IDENTIFICATION DIVISION.
PROGRAM-ID. POS-MACHINE.
DATA DIVISION.
    WORKING-STORAGE SECTION.
          01 CARD_ID PIC X(19).
          01 FIRST_ROW PIC X(4).
              88 CREDIT_COMBINATION VALUE 'AABB', 'IT22', '1234', 'AAAA', 'ABAB', 'BSIT', 'STB0', '0000'. 
          01 SECOND_ROW PIC X(4).
          01 THIRD_ROW PIC X(4).
          01 FOURTH_ROW PIC X(4).
          01 CREDIT_LIMIT PIC 9(6).
          
          01 DEBIT_CARD PIC X(19).
          01 CREDIT_CARD PIC X(19).
          01 CURRENT_SAVINGS PIC 9(6).
           01 BALANCE PIC 9(7).

PROCEDURE DIVISION.
 
DISPLAY 'Card ID:'.
ACCEPT CARD_ID.

UNSTRING CARD_ID DELIMITED BY '-'
    INTO FIRST_ROW, SECOND_ROW, THIRD_ROW, FOURTH_ROW
 END-UNSTRING

IF SECOND_ROW NOT EQUAL TO '3133' 
    IF CREDIT_COMBINATION
       MOVE CARD_ID TO CREDIT_CARD
       DISPLAY 'CREDIT'
    ELSE   
       MOVE CARD_ID TO DEBIT_CARD
       DISPLAY 'DEBIT'
    END-IF
 ELSE    
    DISPLAY 'Transaction cannot proceed.'
 END-IF

STOP RUN.

CodePudding user response:

if you are using online compiler possibly you need to give your input string in STDIN. With the given input string it should work properly.

instead of Evaluate true series of statments following can be used, same way it is used in the following statement.

IF CREDIT_COMBINATION THEN
   MOVE CARD_ID TO CREDIT_CARD
ELSE
   MOVE CARD_ID TO DEBIT_CARD
END-IF

CodePudding user response:

I ran your program and got:

Card ID:
Card ID after UNSTRING: 9876 1245 A012 AERG
FIRST ROW: 9876
DEBIT

so it seems good,,

If your input is good, it should work,

you can write less code by doing the following:

instead of:

INSPECT CARD_ID REPLACING ALL "-" BY SPACE. 
UNSTRING CARD_ID DELIMITED BY SPACE INTO FIRST_ROW, SECOND_ROW, THIRD_ROW, 
FOURTH_ROW
END-UNSTRING.

you can do:

 UNSTRING CARD_ID DELIMITED BY '-'
    INTO FIRST_ROW, SECOND_ROW, THIRD_ROW, FOURTH_ROW
 END-UNSTRING

and like cobp mention, instead of Evaluate true series you can write:

 IF SECOND_ROW NOT EQUAL TO '3133' 
    IF CREDIT_COMBINATION
       MOVE CARD_ID TO CREDIT_CARD
       DISPLAY 'CREDIT'
    ELSE   
       MOVE CARD_ID TO DEBIT_CARD
       DISPLAY 'DEBIT'
    END-IF
 ELSE    
    DISPLAY 'Transaction cannot proceed.'
 END-IF

this is the result I got:

  Card ID: 9876-1245-A012-AERG
  DEBIT
  •  Tags:  
  • Related