Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OPEN "Region1.txt" FOR INPUT AS #1
- OPEN "1st region report.txt" FOR OUTPUT AS #2
- '$dynamic 'https://en.wikibooks.org/wiki/QBasic/Arrays_and_Types ;;;; Quick google search helped
- ' I had a issue getting the count to work. turns out you cannot do that count = count + 1 without a dynamic array. this enables dynamic arrays
- 'all that does is enable it to go from a predetermined count variable, to a dynamic count variable. It is a thousand times easier than
- ' doing it any other way;
- DIM school AS STRING
- DIM school(1) AS STRING
- DIM win AS SINGLE
- DIM win(1) AS SINGLE
- DIM loss AS SINGLE
- DIM loss(1) AS SINGLE
- DIM total(1) AS SINGLE
- DIM winperc(1) AS DOUBLE
- 'seems odd at first but two counters that are similar needed a counter, i needed to use count for something else
- 'so bubble and gum are two similar short phrases that meet the programming convention. similar to foo and bar, and sequential so I know
- ' bubble refers to the first counter, and gum to the second
- DIM bubble AS SINGLE
- DIM gum AS SINGLE
- count = 0
- DO WHILE NOT EOF(1)
- INPUT #1, school, win, loss
- count = count + 1
- 'this code counts the number of lines of information it expects to take in;
- 'this was a really elegant solution to reuse this code for later projects in this class
- LOOP
- CLOSE #1
- REDIM school(count) AS STRING
- REDIM win(count) AS SINGLE
- REDIM loss(count) AS SINGLE
- REDIM total(count) AS SINGLE
- REDIM winperc(count) AS DOUBLE
- OPEN "Region1.txt" FOR INPUT AS #1
- FOR count = 0 TO count - 1
- INPUT #1, school(count), win(count), loss(count)
- NEXT
- 'code still needs to use each array to calculate the win percentage and the total, so lets do the total!
- 'these are simple counters that don't need to be dimensioned, count is already in use. so foo/bar etc. is conventionally used for one off counters or i j or k
- ' i chose to use bubble gum because I enjoy candy.
- FOR bubble = 0 TO count - 1
- total(bubble) = win(bubble) + loss(bubble)
- NEXT
- 'now we calculate win percent,I chose to use gum and bubble as they are relatively related and are simply counters so you can tell they
- 'are similar functions
- FOR gum = 0 TO count - 1
- winperc(gum) = (win(gum) / total(gum)) * 100
- PRINT school(gum)
- ' lack of debugging means this had to be used instead
- ' PRINT USING "###.##%"; winperc(gum)
- 'WRITE #2, school(gum), winperc(gum)
- NEXT
- 'now we populate the file output according to the included printer spacing chart
- PRINT #2, TAB(12); "1st region",
- PRINT #2,
- PRINT #2, "school district"; TAB(18); "wins"; TAB(23); "losses"; TAB(30); "win%"
- PRINT #2, "---------------"; TAB(18); "----"; TAB(23); "------"; TAB(30); "----"
- FOR j = 0 TO count - 1
- PRINT #2, school(j); TAB(18); USING "##"; win(j);
- PRINT #2, TAB(23); USING "##"; loss(j);
- PRINT #2, TAB(30); USING "###.##%"; winperc(j)
- NEXT
- CLOSE #1
- CLOSE #2
- CLEAR
- PRINT "the file '1st region report.txt' has been created and tabulated"
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement