SHARE
TWEET

Untitled

a guest Dec 7th, 2018 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     ' Previously had reusable code here, it was removed
  28.     ' it was easier to just use dynamic arrays, included documentation on instantiating dynamic arrays above which is a pain
  29.     ' previously I tried to instantiate the length of the arrays after counting, but it was less reusable than an example
  30.     'using dynamic memory allocative arrays;
  31.     'this code does not work if you do not enable dynamic arrays.
  32.     'this code is ugly but it counts the amount of information it expects to take in;
  33.     'this sounds really stupid but its just a limitation of the compiler/language
  34.  
  35. LOOP
  36. CLOSE #1
  37. REDIM school(count) AS STRING
  38. REDIM win(count) AS SINGLE
  39. REDIM loss(count) AS SINGLE
  40. REDIM total(count) AS SINGLE
  41. REDIM winperc(count) AS DOUBLE
  42. OPEN "Region1.txt" FOR INPUT AS #1
  43. FOR count = 0 TO count - 1
  44.     INPUT #1, school(count), win(count), loss(count)
  45. NEXT
  46.  
  47.  
  48. 'code still needs to use each array to calculate the win percentage and the total, so lets do the total!
  49. '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
  50. ' i chose to use bubble gum because I enjoy candy.
  51.  
  52.  
  53. FOR bubble = 0 TO count - 1
  54.     total(bubble) = win(bubble) + loss(bubble)
  55. NEXT
  56.  
  57. '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
  58. 'are similar functions
  59.  
  60. FOR gum = 0 TO count - 1
  61.     winperc(gum) = (win(gum) / total(gum)) * 100
  62.     PRINT school(gum)
  63.     ' lack of debugging means this had to be used instead
  64.     ' PRINT USING "###.##%"; winperc(gum)
  65.     'WRITE #2, school(gum), winperc(gum)
  66.  
  67. NEXT
  68. 'now we populate the file output according to the included printer spacing chart
  69. PRINT #2, TAB(12); "1st region",
  70. PRINT #2,
  71. PRINT #2, "school district"; TAB(18); "wins"; TAB(23); "losses"; TAB(30); "win%"
  72. PRINT #2, "---------------"; TAB(18); "----"; TAB(23); "------"; TAB(30); "----"
  73.  
  74. FOR j = 0 TO count - 1
  75.     PRINT #2, school(j); TAB(18); USING "##"; win(j);
  76.     PRINT #2, TAB(23); USING "##"; loss(j);
  77.     PRINT #2, TAB(30); USING "###.##%"; winperc(j)
  78. NEXT
  79. CLOSE #1
  80. CLOSE #2
  81. CLEAR
  82. PRINT "the file '1st region report.txt' has been created and tabulated"
  83. END
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top