Advertisement
Guest User

Untitled

a guest
Dec 7th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 2.93 KB | None | 0 0
  1. OPEN "Region1.txt" FOR INPUT AS #1
  2. OPEN "1st region report.txt" FOR OUTPUT AS #2
  3. '$dynamic        'https://en.wikibooks.org/wiki/QBasic/Arrays_and_Types ;;;; Quick google search helped
  4. ' 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
  5. '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
  6. ' doing it any other way;
  7. DIM school AS STRING
  8. DIM school(1) AS STRING
  9. DIM win AS SINGLE
  10. DIM win(1) AS SINGLE
  11. DIM loss AS SINGLE
  12. DIM loss(1) AS SINGLE
  13. DIM total(1) AS SINGLE
  14. DIM winperc(1) AS DOUBLE
  15. 'seems odd at first but two counters that are similar needed a counter, i needed to use count for something else
  16. 'so bubble and gum are two similar short phrases that meet the programming convention. similar to foo and bar, and sequential so I know
  17. ' bubble refers to the first counter, and gum to the second
  18. DIM bubble AS SINGLE
  19. DIM gum AS SINGLE
  20.  
  21.  
  22.  
  23. count = 0
  24. DO WHILE NOT EOF(1)
  25.     INPUT #1, school, win, loss
  26.     count = count + 1
  27.     'this code counts the number of lines of information it expects to take in;
  28.     'this was a really elegant solution to reuse this code for later projects in this class
  29.  
  30. LOOP
  31. CLOSE #1
  32. REDIM school(count) AS STRING
  33. REDIM win(count) AS SINGLE
  34. REDIM loss(count) AS SINGLE
  35. REDIM total(count) AS SINGLE
  36. REDIM winperc(count) AS DOUBLE
  37. OPEN "Region1.txt" FOR INPUT AS #1
  38. FOR count = 0 TO count - 1
  39.     INPUT #1, school(count), win(count), loss(count)
  40. NEXT
  41.  
  42.  
  43. 'code still needs to use each array to calculate the win percentage and the total, so lets do the total!
  44. '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
  45. ' i chose to use bubble gum because I enjoy candy.
  46.  
  47.  
  48. FOR bubble = 0 TO count - 1
  49.     total(bubble) = win(bubble) + loss(bubble)
  50. NEXT
  51.  
  52. '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
  53. 'are similar functions
  54.  
  55. FOR gum = 0 TO count - 1
  56.     winperc(gum) = (win(gum) / total(gum)) * 100
  57.     PRINT school(gum)
  58.     ' lack of debugging means this had to be used instead
  59.     ' PRINT USING "###.##%"; winperc(gum)
  60.     'WRITE #2, school(gum), winperc(gum)
  61.  
  62. NEXT
  63. 'now we populate the file output according to the included printer spacing chart
  64. PRINT #2, TAB(12); "1st region",
  65. PRINT #2,
  66. PRINT #2, "school district"; TAB(18); "wins"; TAB(23); "losses"; TAB(30); "win%"
  67. PRINT #2, "---------------"; TAB(18); "----"; TAB(23); "------"; TAB(30); "----"
  68.  
  69. FOR j = 0 TO count - 1
  70.     PRINT #2, school(j); TAB(18); USING "##"; win(j);
  71.     PRINT #2, TAB(23); USING "##"; loss(j);
  72.     PRINT #2, TAB(30); USING "###.##%"; winperc(j)
  73. NEXT
  74. CLOSE #1
  75. CLOSE #2
  76. CLEAR
  77. PRINT "the file '1st region report.txt' has been created and tabulated"
  78. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement