News:

Welcome to RetroCoders Community

Main Menu

GW Basic Quitting Smoking Program

Started by ron77, Nov 20, 2023, 02:49 PM

Previous topic - Next topic

ron77

10 REM QUIT SMOKING PROGRAM
20 REM BY RON77 2023
30 REM INITIALIZE VARIABLES
40 LOGFILE$="QUIT.LOG":SWITCHFILE$= "SWITCH.TXT": S$="": ROW=0: QUIT=0: DT$="":D$="": M$="": Y$="": CHOICE=0: FLAG=0: CIGS=0: COST=0: YEARS=0: LIFE=0
45 GOSUB 8000: REM CHECK FOR SWITCH FILE
50 REM MAIN PROGRAM LOOP
60 SCREEN 0: WIDTH 80:KEY OFF: COLOR 15,0: CLS:S$="QUIT SMOKING PROGRAM": ROW=3: GOSUB 5000
70 S$="BY RON77 2023": ROW=4: GOSUB 5000
80 WHILE INKEY$="": WEND
90 CLS
100 S$="QUIT SMOKING PROGRAM": ROW=3: GOSUB 5000
120 IF QUIT = 0 THEN S$="1. I'M READY TO QUIT": ROW=5: GOSUB 5000 :
130 IF QUIT = 1 AND FLAG = 1 THEN S$="1. VIEW DAYS WITHOUT SMOKING": ROW=5: GOSUB 5000
140 IF QUIT = 1 AND FLAG=1 THEN S$="2. VIEW MONEY SAVED": ROW=6: GOSUB 5000
150 IF QUIT = 1 AND FLAG =1 THEN S$="3. VIEW CIGARETTES NOT SMOKED": ROW=7: GOSUB 5000
155 IF QUIT = 1 AND FLAG = 1 THEN S$="4. I STARTED SMOKING AGAIN": ROW=8: GOSUB 5000
160 IF QUIT = 0 THEN S$="2. SMOKING CALCULATOR": ROW=6: GOSUB 5000
170 INPUT "ENTER CHOICE: ", CHOICE
180 IF QUIT = 0 AND CHOICE = 1 THEN GOSUB 1000: CHOICE=0: GOTO 90
190 IF QUIT = 0 AND CHOICE = 2 THEN GOSUB 2000: CHOICE=0 : GOTO 90
200 IF QUIT = 1 AND CHOICE = 1 THEN GOSUB 3000 : CHOICE=0 : GOTO 90
210 IF QUIT = 1 AND CHOICE = 2 THEN GOSUB 4000 : CHOICE=0 : GOTO 90
220 IF QUIT = 1 AND CHOICE = 3 THEN GOSUB 6000: CHOICE=0 : GOTO 90
225 IF QUIT = 1 AND CHOICE = 4 THEN GOSUB 7000 : CHOICE=0 : GOTO 90
230 IF QUIT = 0 AND CHOICE < 1 AND CHOICE < 2 THEN GOTO 170
240 IF QUIT = 1 AND CHOICE < 1 AND CHOICE < 4 THEN GOTO 170
250 GOTO 90

1000 REM QUIT SMOKING ROUTINE
1010 OPEN "A",#1,LOGFILE$
1020 DT$=DATE$
1030 PRINT #1,DT$
1032 PRINT #1, FLAG
1035 IF FLAG = 1 THEN PRINT #1, CIGS, COST, YEARS
1040 CLOSE #1
1050 QUIT=1
1051 OPEN "O",#1,SWITCHFILE$
1052 PRINT #1, QUIT
1053 PRINT #1, FLAG
1054 CLOSE #1
1060 CLS
1070 S$="YOU STARTED QUITTING SMOKING": ROW=3: GOSUB 5000
1080 S$="ON "+DT$: ROW=4: GOSUB 5000
1090 S$="PRESS ANY KEY TO CONTINUE": ROW=6: GOSUB 5000
1100 WHILE INKEY$="": WEND
1110 RETURN

2000 REM SMOKING CALCULATOR ROUTINE
2010 CLS
2015 FLAG=1
2020 S$="SMOKING CALCULATOR": ROW=3: GOSUB 5000
2030 INPUT "HOW MANY CIGARETTES DO YOU SMOKE A DAY? ", CIGS
2040 INPUT "HOW MUCH DOES A PACK OF CIGARETTES COST? ", COST
2050 INPUT "HOW MANY YEARS HAVE YOU BEEN SMOKING? ", YEARS
2060 CIGSYEARS=CIGS*365
2070 CIGSTOTAL=CIGSYEARS*YEARS
2080 COSTTOTAL=COST*(CIGSTOTAL/20)
2082 LIFE = (((CIGSTOTAL*5)/60)/24)/365
2090 CLS:S$="YOU HAVE SPENT $"+MID$(STR$(COSTTOTAL),2)+" ON CIGARETTES": ROW=5: GOSUB 5000
2100 S$="YOU HAVE SMOKED "+MID$(STR$(CIGSTOTAL),2)+" CIGARETTES": ROW=6: GOSUB 5000
2110 S$="YOU HAVE LOST "+MID$(STR$(LIFE),2)+" YEARS OF YOUR LIFE": ROW=7: GOSUB 5000
2120 S$="PRESS ANY KEY TO CONTINUE": ROW=9: GOSUB 5000
2130 WHILE INKEY$="": WEND
2140 RETURN

3000 REM DAYS WITHOUT SMOKING ROUTINE
3010 CLS
3020 OPEN "I",#1,LOGFILE$
3030 INPUT #1, DT$
3032 INPUT #1, FLAG
3035 IF FLAG = 1 THEN INPUT #1, CIGS, COST, YEARS
3040 CLOSE #1
3050 REM CALCULATE DAYS WITHOUT SMOKING
3060 DTP$=DATE$
3061 EM$=MID$(DTP$,1,2)
3062 ED$=MID$(DTP$,4,2)
3063 EY$=MID$(DTP$,7,4)
3064 SM$=MID$(DT$,1,2)
3065 SD$=MID$(DT$,4,2)
3066 SY$=MID$(DT$,7,4)
3070 REM
3080 REM
3090 M = VAL(SM$): D = VAL(SD$): Y = VAL(SY$): GOSUB 3500: SJ = JDN
3100 M = VAL(EM$): D = VAL(ED$): Y = VAL(EY$): GOSUB 3500: EJ = JDN
3110 DD = EJ - SJ
3120 S$="NUMBER OF DAYS: "+MID$(STR$(DD),2): ROW=5: GOSUB 5000
3125 WHILE INKEY$="": WEND
3130 RETURN

3500 REM SUBROUTINE TO CONVERT DATE TO JULIAN DAY NUMBER
3510 REM
3520 A = (14 - M) / 12
3530 Y = Y + 4800 - A
3540 M = M + 12 * A - 3
3560 JDN = D + ((153 * M + 2) / 5) + 365 * Y + Y / 4 - Y / 100 + Y / 400 - 32045
3570 RETURN

4000 REM MONEY SAVED ROUTINE
4010 CLS
4020 OPEN "I",#1,LOGFILE$
4030 INPUT #1, DT$
4032 INPUT #1, FLAG
4035 IF FLAG = 1 THEN INPUT #1, CIGS, COST, YEARS
4040 CLOSE #1
4050 REM CALCULATE MONEY SAVED
4060 DTP$=DATE$
4061 EM$=MID$(DTP$,1,2)
4062 ED$=MID$(DTP$,4,2)
4063 EY$=MID$(DTP$,7,4)
4064 SM$=MID$(DT$,1,2)
4065 SD$=MID$(DT$,4,2)
4066 SY$=MID$(DT$,7,4)
4070 REM
4080 REM
4090 M = VAL(SM$): D = VAL(SD$): Y = VAL(SY$): GOSUB 3500: SJ = JDN
4100 M = VAL(EM$): D = VAL(ED$): Y = VAL(EY$): GOSUB 3500: EJ = JDN
4110 DD = EJ - SJ
4120 CIGARETTES = DD * CIGS
4130 MONEY = CIGARETTES * COST / 20
4140 S$="MONEY SAVED: $"+MID$(STR$(MONEY),2) : ROW=5: GOSUB 5000
4145 WHILE INKEY$="": WEND
4150 RETURN


5000 REM CENTER PRINT ROUTINE
5010 LOCATE ROW,(80-LEN(S$))/2: PRINT S$
5020 RETURN

6000 REM CIGARETTES NOT SMOKED ROUTINE
6010 CLS
6020 OPEN "I",#1,LOGFILE$
6030 INPUT #1, DT$
6032 INPUT #1, FLAG
6035 IF FLAG = 1 THEN INPUT #1, CIGS, COST, YEARS
6040 CLOSE #1
6050 REM CALCULATE CIGARETTES NOT SMOKED
6060 DTP$=DATE$
6061 EM$=MID$(DTP$,1,2)
6062 ED$=MID$(DTP$,4,2)
6063 EY$=MID$(DTP$,7,4)
6064 SM$=MID$(DT$,1,2)
6065 SD$=MID$(DT$,4,2)
6066 SY$=MID$(DT$,7,4)
6070 REM
6080 REM
6090 M = VAL(SM$): D = VAL(SD$): Y = VAL(SY$): GOSUB 3500: SJ = JDN
6100 M = VAL(EM$): D = VAL(ED$): Y = VAL(EY$): GOSUB 3500: EJ = JDN
6110 DD = EJ - SJ
6120 CIGARETTES = DD * CIGS
6130 S$="CIGARETTES NOT SMOKED: "+MID$(STR$(CIGARETTES),2): ROW=5: GOSUB 5000
6135 WHILE INKEY$="": WEND
6140 RETURN

7000 REM STARTED SMOKING AGAIN ROUTINE
7010 CLS
7011 PRINT "ARE YOU SURE YOU WANT TO START SMOKING AGAIN? (Y/N)"
7012 INPUT, S$
7013 IF START$ = "N" OR START$="n" THEN RETURN
7015 FLAG=0: QUIT=0
7020 KILL LOGFILE$
7025 OPEN "O",#1,SWITCHFILE$
7026 PRINT #1, QUIT
7027 PRINT #1, FLAG
7030 CLOSE #1
7040 RETURN

8000 REM CHECK FOR SWITCH FILE
8010 OPEN "I",#1,SWITCHFILE$
8020 INPUT #1, QUIT
8025 INPUT #1, FLAG
8030 CLOSE #1
8040 RETURN

file "SWITCH.TXT" content
0
0