Counter counting by two?

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
Guest

Counter counting by two?

Post by Guest »

Hi all, I have written a QBasic program and everything seems to function. However, my counter counts by two instead of one. Here is the code for the program:

Code: Select all

DECLARE SUB B000Initialize ()
DECLARE SUB B010Process ()
DECLARE SUB B020Print ()
DECLARE SUB C000ReadRecord ()
DECLARE SUB C010PrintHeading (strTitle AS STRING)
CLS
DIM SHARED intEOF AS INTEGER
DIM SHARED intCount AS INTEGER
DIM SHARED intResCount AS INTEGER
DIM SHARED sngResStudent AS SINGLE
DIM SHARED sngResTuitionCount AS SINGLE
DIM SHARED sngNonResTuitionCount AS SINGLE
DIM SHARED sngTotalTuitionCount AS SINGLE
DIM SHARED sngNonResStudent AS SINGLE
DIM SHARED intNonResCount AS INTEGER
DIM SHARED sngIndividualTuition AS SINGLE
DIM SHARED strStudentName AS STRING
DIM SHARED sngCredits AS SINGLE
DIM SHARED strResidencyCode AS STRING
DIM SHARED intLineCount AS INTEGER
DIM SHARED intPageCount AS INTEGER
DIM SHARED intMaxLines AS INTEGER
CALL B000Initialize
IF intEOF = 1 THEN
        PRINT "File Empty"
ELSE
        DO WHILE intEOF = 0
                CALL B010Process
        LOOP
       
        CALL B020Print
END IF
CLOSE #1
END

SUB B000Initialize
intMaxLines = 12
intLineCount = intMaxLines
intPageCount = 1
intEOF = 0
intCount = 0
intResCount = 0
intNonResCount = 0
sngTotalTuition = 0
OPEN "enroll.txt" FOR INPUT AS #1
CALL C000ReadRecord
END SUB

SUB B010Process
IF intLineCount >= intMaxLines THEN
        CALL C010PrintHeading("Student Tuition Report")
END IF
        intCount = intCount + 1
PRINT intCount, strStudentName, strResidencyCode, sngCredits,
IF intLineCount < intCount AND UCASE$(strResidencyCode) = "R" THEN
        sngResStudent = sngCredits * 55
        PRINT (sngResStudent)
        intResCount = intResCount + 1
        sngResTuitionCount = sngResTuitionCount + sngResStudent
END IF
        intLineCount = intLineCount + 1
IF intLineCount < intCount AND UCASE$(strResidencyCode) = "N" THEN
        sngNonResStudent = sngCredits * 85
        PRINT (sngNonResStudent)
        intNonResCount = intNonResCount + 1
        sngNonResTuitionCount = sngNonResTuitionCount + sngNonResStudent
END IF
        IF UCASE$(strResidencyCode) <> "R" AND UCASE$(strResidencyCode) <> "N" THEN
        PRINT "Invalid Residency"
     
END IF
intCount = intCount + 1
CALL C000ReadRecord
END SUB

SUB B020Print

sngTotalTuitionCount = sngResTuitionCount + sngNonResTuitionCount

PRINT
PRINT "The total amount of resident students is"; intResCount
PRINT "The total amount of non-resident students is"; intNonResCount
PRINT "The total tuition due is: ";
PRINT USING "$$,###.##"; sngTotalTuitionCount
END SUB

SUB C000ReadRecord
IF EOF(1) THEN
        intEOF = 1
ELSE
        INPUT #1, strStudentName, strResidencyCode, sngCredits
END IF
END SUB

SUB C010PrintHeading (strTitle AS STRING)
DIM strNewPage AS STRING
PRINT
PRINT "Press enter to see page"; intPageCount
INPUT strNewPage
CLS
PRINT strTitle, "Page"; intPageCount
PRINT
PRINT "Number", "Student Name", "Residency", "Credits", "Tuition Due"
PRINT
intLineCount = 0
intPageCount = intPageCount + 1
END SUB
Any ideas as to why my counter isn't counting by one would be appreciated.
Antoni
Veteran
Posts: 132
Joined: Wed Jun 15, 2005 3:01 pm
Contact:

Post by Antoni »

I see four counters in your code, which one does not work?
If you're speaking about intcount you are specifically increasing it by 1 twice every call to B010Process. Is this the problem?
Seb McClouth

Post by Seb McClouth »

I think I'd be able to rewrite it for you with some Pascal-code but you'll have to wait till next week, if you're lucky this Tuesday or else friday.

grtz
Seb
Guest

Post by Guest »

Antoni wrote:I see four counters in your code, which one does not work?
If you're speaking about intcount you are specifically increasing it by 1 twice every call to B010Process. Is this the problem?
Yes, my problem is with intCount counting by two.
But when I remove the second intCount = intCount + 1 located here:
IF UCASE$(strResidencyCode) <> "R" AND UCASE$(strResidencyCode) <> "N" THEN
PRINT "Invalid Residency"

END IF
intCount = intCount + 1
CALL C000ReadRecord
END SUB
The names and residency codes all get mixed up into different columns on the first page. But on the second page the formatting is fine, and the counter counts by one.
I think I just need to initiliaze a different counter at the end of that last END IF in B010Process, but i'm not sure which count I should end that statement with. :?
Post Reply