Author Topic: Check the Cash Register Receipt  (Read 2542 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Check the Cash Register Receipt
« on: August 20, 2019, 03:59:43 pm »
Did you ever come home from store and wonder where all your money went?

You look at the receipt and the prices look OK, but wonder, "Did the register add the stuff up right?"

I did today, (again) so a made a little proggie to reassure myself the register is working right.
Ha! I trust a QB64 program more!

It seems to be working OK or all the adders are conspiring against me... :-))
Code: QB64: [Select]
  1. _TITLE "Adding machine, use c to clear total, enter again to repeat an add, R to review tape" 'B+ 2019-08-20
  2. REDIM tape(0) AS STRING
  3.  
  4. WHILE _KEYDOWN(27) = 0
  5.     k$ = INKEY$
  6.     IF LEN(k$) THEN
  7.         IF INSTR("-.0123456789", k$) THEN build$ = build$ + k$: PRINT k$;
  8.         IF ASC(k$) = 8 AND LEN(build$) THEN build$ = LEFT$(build$, LEN(build$) - 1): PRINT: PRINT build$;
  9.         IF ASC(k$) = 13 THEN
  10.             IF build$ = "" AND lastBuild$ <> "" THEN
  11.                 r = r + 1
  12.                 total = total + VAL(lastBuild$)
  13.                 LOCATE , 1: PRINT lastBuild$;
  14.                 LOCATE , 30: PRINT total, r
  15.                 s$ = SPACE$(60)
  16.                 MID$(s$, 1, LEN(lastBuild$)) = lastBuild$
  17.                 st$ = STR$(total)
  18.                 MID$(s$, 30, LEN(st$)) = st$
  19.                 st$ = STR$(r)
  20.                 MID$(s$, 45, LEN(st$)) = st$
  21.                 sAppend tape(), s$
  22.             ELSE
  23.                 r = 1
  24.                 total = total + VAL(build$)
  25.                 LOCATE , 30: PRINT total
  26.                 s$ = SPACE$(60)
  27.                 MID$(s$, 1, LEN(build$)) = build$
  28.                 st$ = STR$(total)
  29.                 MID$(s$, 30, LEN(st$)) = st$
  30.                 sAppend tape(), s$
  31.                 lastBuild$ = build$
  32.                 build$ = ""
  33.             END IF
  34.         END IF
  35.         IF UCASE$(k$) = "C" THEN
  36.             CLS: total = 0: build$ = ""
  37.             st$ = STRING$(60, "-")
  38.             sAppend tape(), st$
  39.         END IF
  40.         IF UCASE$(k$) = "R" THEN
  41.             _KEYCLEAR
  42.             show tape()
  43.             CLS
  44.             LOCATE , 1: PRINT "Current total: ";
  45.             LOCATE , 30: PRINT total
  46.         END IF
  47.     END IF
  48.     _LIMIT 60
  49.  
  50. 'append to the string array the string item
  51. SUB sAppend (arr() AS STRING, item AS STRING)
  52.     REDIM _PRESERVE arr(LBOUND(arr) TO UBOUND(arr) + 1) AS STRING
  53.     arr(UBOUND(arr)) = item
  54.  
  55. SUB show (arr() AS STRING)
  56.     DIM lb AS LONG, ub AS LONG, top AS LONG, i AS LONG, row AS LONG, prevrow AS LONG, n AS LONG
  57.     lb = LBOUND(arr): ub = UBOUND(arr)
  58.     IF ub - lb + 1 < 21 THEN top = ub ELSE top = lb + 19
  59.     CLS: PRINT "press any key to quit scroller..."
  60.     LOCATE 2, 1
  61.     FOR i = lb TO top
  62.         PRINT arr(i)
  63.     NEXT
  64.     DO
  65.         IF ub - lb + 1 > 20 THEN
  66.             DO WHILE _MOUSEINPUT
  67.                 IF row >= lb THEN row = row + _MOUSEWHEEL ELSE row = lb 'prevent under scrolling
  68.                 IF row > ub - 19 THEN row = ub - 19 'prevent over scrolling
  69.                 IF prevrow <> row THEN 'look for a change in row value
  70.                     IF row >= lb AND row <= ub - 19 THEN
  71.                         CLS: PRINT "press any key to quit scroller..."
  72.                         LOCATE 2, 1
  73.                         FOR n = row TO row + 19
  74.                             PRINT arr(n)
  75.                         NEXT
  76.                     END IF
  77.                 END IF
  78.                 prevrow = row 'store previous row value
  79.             LOOP
  80.         END IF
  81.     LOOP UNTIL INKEY$ > ""
  82.  
  83.  

R to Review the tape, to repeat items just press enter again, will get a repeat count with price and total.

Probably will work with checkbooks too.
« Last Edit: August 20, 2019, 04:02:58 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: Check the Cash Register Receipt
« Reply #1 on: August 20, 2019, 04:46:18 pm »
"Proggie"? Interesting. Do you pronounce "Newcastlle" as "new castle" or "new carstle"? Guess where I'm going with this... lol
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Check the Cash Register Receipt
« Reply #2 on: August 20, 2019, 05:13:35 pm »
Cool little adding proggie! LOL Johno "proggie" goes back to at least the 90's. Not sure where it started, probably California.

I just found out how it started... lol from hackers. Oh well...

https://www.urbandictionary.com/define.php?term=proggie
« Last Edit: August 20, 2019, 05:17:20 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Check the Cash Register Receipt
« Reply #3 on: August 20, 2019, 05:39:04 pm »
hmm... now you have me wondering where I picked up that term, probably from an Italian MASM developer and lover of Basic.

Being close to Cleveland, I suppose I should be telling you guys of perogies but I never had any, but with bacon I'll try anything. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Check the Cash Register Receipt
« Reply #4 on: April 05, 2022, 09:55:42 am »
Update: Now done with Long Integers for cents and using dollars$ function to display with decimal.
Oh yeah, I put the Input line at the bottom and your "paper" tape is above and will show your last 20 lines.

Now, no more the crazy stuff the default Single adds or subtracts from a number.

Instructions (some in the title):
"q" enter to quit (or just use the normal way).
"r" enter lets you read / review the paper tape simulation, scrollable with mouse wheel.
"c" enter lets you clear the screen, tape and running total
just enter allows you to add (or subtract if negative) the last amount entered.
So just enter positive and negative numbers for a running total to check receipt or balance checking account.

Code: QB64: [Select]
  1. _Title "Adding machine, use c to clear total, enter again to repeat an add, R to review tape" 'B+ 2019-08-20
  2. ' 2022-04-04 overhaul with input Cents (no decimal)
  3.  
  4. ReDim tape(0) As String
  5. Dim test$
  6. Dim As Long total, amt, quit, row, start, i
  7. row = 0
  8.  
  9.     Locate 25, 1: Input "Enter Cents Amount (no decimal), q to quit "; test$
  10.     If test$ = "q" Then
  11.         quit = -1
  12.     ElseIf test$ = "c" Then
  13.         Cls: total = 0
  14.         row = 0
  15.         ReDim tape(0) As String
  16.     ElseIf test$ = "r" Then
  17.         _KeyClear
  18.         show tape()
  19.         GoSub AndDisplay
  20.     ElseIf allNumber%(test$) Then
  21.         View Print 1 To 21
  22.         amt = Val(test$)
  23.         GoSub addAndDisplay
  24.     ElseIf test$ = "" Then ' just enter then repeat last amt
  25.         GoSub addAndDisplay
  26.     End If
  27.     _Limit 60
  28. Loop Until quit
  29.  
  30. addAndDisplay:
  31. total = total + amt
  32. s$ = dollars$(amt) + Space$(20 - Len(dollars$(amt)) - Len(dollars$(total))) + dollars$(total)
  33. sAppend tape(), s$
  34. row = row + 1
  35. AndDisplay:
  36. If row > 20 Then start = row - 20 Else start = 1
  37. For i = start To row
  38.     Print tape(i)
  39.  
  40. Function dollars$ (cents As Long)
  41.     s$ = _Trim$(Str$(cents))
  42.     If Left$(s$, 1) = "-" Then sign$ = "-": s$ = Mid$(s$, 2) Else sign$ = ""
  43.     If Len(s$) = 1 Then
  44.         s$ = sign$ + "0.0" + s$
  45.     ElseIf Len(s$) = 2 Then
  46.         s$ = sign$ + "0." + s$
  47.     Else
  48.         s$ = sign$ + Mid$(s$, 1, Len(s$) - 2) + "." + Mid$(s$, Len(s$) - 1)
  49.     End If
  50.     dollars$ = s$
  51.  
  52. Function allNumber% (s$)
  53.     If Len(s$) = 0 Then Exit Function
  54.     For i = 1 To Len(s$)
  55.         If InStr("-1234567890", Mid$(s$, i, 1)) <= 0 Then Exit Function 'done return 0
  56.     Next
  57.     allNumber% = -1
  58.  
  59. 'append to the string array the string item
  60. Sub sAppend (arr() As String, item As String)
  61.     ReDim _Preserve arr(LBound(arr) To UBound(arr) + 1) As String
  62.     arr(UBound(arr)) = item
  63.  
  64. Sub show (arr() As String)
  65.     Dim lb As Long, ub As Long, top As Long, i As Long, row As Long, prevrow As Long, n As Long
  66.     lb = LBound(arr): ub = UBound(arr)
  67.     If ub - lb + 1 < 21 Then top = ub Else top = lb + 19
  68.     Cls: Print "press any key to quit scroller..."
  69.     Locate 2, 1
  70.     For i = lb To top
  71.         Print arr(i)
  72.     Next
  73.     Do
  74.         If ub - lb + 1 > 20 Then
  75.             Do While _MouseInput
  76.                 If row >= lb Then row = row + _MouseWheel Else row = lb 'prevent under scrolling
  77.                 If row > ub - 19 Then row = ub - 19 'prevent over scrolling
  78.                 If prevrow <> row Then 'look for a change in row value
  79.                     If row >= lb And row <= ub - 19 Then
  80.                         Cls: Print "press any key to quit Review of tape..."
  81.                         Locate 2, 1
  82.                         For n = row To row + 19
  83.                             Print arr(n)
  84.                         Next
  85.                     End If
  86.                 End If
  87.                 prevrow = row 'store previous row value
  88.             Loop
  89.         End If
  90.     Loop Until InKey$ > ""
  91.  
  92.  
  93.  

PS If Long fits 10 years of seconds then that's how many cents the Total may add to before it's limit fails.
« Last Edit: April 05, 2022, 10:14:15 am by bplus »