Carcharge wont print :(

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
azure8bit
Newbie
Posts: 4
Joined: Tue Oct 11, 2016 11:28 pm

Carcharge wont print :(

Post by azure8bit »

Im having trouble getting CarCharge to print out. If someone could help me. I would appreciate it.

Code: Select all

'*************************** PROGRAM VARIABLES *****************************
CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
END
'***************************** INITIALIZE VARIABLES *************************

InitializeVariables:
H1$ = " [CUSTOMER NAME]     [CAR TYPE]     [DAYS HELD]     [MILES TRAVELED] [CHARGE]  "
D1$ = " [\      \]          [\          \]    [##]         [#,###]     [####]  "
t1$ = "                      [AUTO RENTAL COMPANY] "
return
'**************************** PRINT HEADINGS ********************************
PrintHeadings:
print
print
print
print t1$
print
print
print h1$
print
RETURN
'*************************** PROCESS DETAIL *********************************
ProcessDetail:
GOSUB ReadData
DO UNTIL UCASE$(NAM$) = "END"
    gosub calculateanswer
    GOSUB PrintDetail
    GOSUB ReadData
LOOP
RETURN
'******************************* CALCULATE ANSWER ****************************
CalculateAnswer:
If Cartype$ = "Compact" then
    CARCHARGE = (10 * DAYS) + (.15 * MILES)
    elseif Cartype$ = "Intermediate" then
    CARCHARGE = (20 * DAYS) + (.18 * MILES)
    elseif Cartype$ = "Large" then
    CARCHARGE = (30 * DAYS) + (.22 * MILES)
end if
return
'******************************* PRINT DETAIL ********************************
PrintDetail:
PRINT USING D1$;NAM$,CarType$,Days,Miles,CarCharge
RETURN
'******************************* READ DATA ***********************************
ReadData:
READ NAM$,CARTYPE$,DAYS,MILES,Carcharge
DATA JONES,LARGE,6,500,0
DATA SMITH,COMPACT,17,3000,0
DATA BAKER,INTERMEDIATE,8,250,0
DATA WILLIAMS,INTERMEDIATE,4,1000,0
DATA WINSTON,LARGE,3,500,0
data end,end,0,0,0
RETURN
'****************************** END OF PROGRAM ***********************************


User avatar
seaBiscuit!
Newbie
Posts: 3
Joined: Sun Dec 18, 2016 8:11 pm
Location: The Internet

Re: Carcharge wont print :(

Post by seaBiscuit! »

Take a look in your CalculateAnswer subroutine. That's where your problem is.

What happens if the Cartype$ variable isn't one of the three options?

What is the value of the Cartype$ variable going into that sub?

Answer those two questions, and you'll have your bugfix! :)
Post Reply