I apologize again for getting anal but it is essential for a novice, as the title of the thread suggests, to understand the components in a program and what they are doing.
Here's our program broken into sections with explanation:
The first three lines clear the screen (CLS). The REM statement is a reminder of what the program is designed to do. The A$ through E$ is data I want printed to the screen to make the output understandable. Otherwise I would have a bunch of meaningless numbers flashing by.
CLS: REM:calculate the percentage of sums for all draws
A$ = "In": B$ = "Drawings, the sum is between": C$ = "and": D$ = "times."
E$ = "Winning Percentage "
These next three lines set the parameters. Y is the low value. Z is the high value. Together they work like an odometer in a car starting at 0,0; 0,1; 0,2; to 27,27. Each time Z reaches 27, Y will go to the next higher digit. The third line, IF Z<Y THEN 520, ensures Z is never less than Y. If so the program will procreed to the NEXT Z statement ad get the next higher digit.
FOR Y = 0 TO 27
FOR Z = 0 TO 27
IF Z < Y THEN 520
We've now set out parameters and in this case we're going to compare those to data in a file. The OPEN statement tells the program to open night3.txt to input the data. Our DO UNTIL EOF(1) tells the program to continue inputting data until it reached the End Of File. The INPUT#1 statement tells the program what data to use. G$ is Game. M is Month, DT is Date. YR is Year. N1 is number one, N2 is number 2, and N3 is number 3. S is sum. I is an interval counter telling the program how many times it has run through this LOOP.
OPEN "H:\QB64\night3.txt" FOR INPUT AS #1 '<-- change the 'H' to the drive where QB64 is located.
DO UNTIL EOF(1)
INPUT #1, G$, M, DT, YR, N1, N2, N3, S
I = I + 1
IF S >= Y AND S <= Z THEN HIT = HIT + 1 <-- This statement checks the sum to see if it is between the low sum Y and the high sum Z. If so then HIT adds 1 to the total.
IF S < Y OR S > Z THEN MISS = MISS + 1 <--- This statement counts the number of times the sum is not between Y and Z.
R = R + 1 (This is an artifact left over from rewrite 9317. Serves no useful purpose, but to make Jimbooble ask questions. Everybody else can ignore it. )
IF S >= Y AND S <= Z THEN HIT = HIT + 1
IF S < Y OR S > Z THEN MISS = MISS + 1
R = R + 1
LOOP
Now that our data is being calculated we can set and watch a blank screen give out eyes something to look at! So let's do that. These statements tell the program what to write to the screen:
'Showme
PRINT A$; I; B$; Y; C$; Z; HIT; D$
PRINT E$; USING "##.###"; (HIT * 100) / I
While the program is displaying the information we want to see, we also want to write that data into a file we can take into Excel. To do that we again use the OPEN statement with a couple of changes. We're going to open the file for APPEND so that we can write to the file. And we're going to open it as file #2. Notice in the WRITE #2 statement, we're only writing the Interval, the low total, the high total, and the percentage of HITS.
'Writeme
OPEN "H:\QB64\sumdata.dat" FOR APPEND AS #2 '<-- change the H to the drive where QB64 is located
WRITE #2, I, Y, Z, (HIT * 100) / I
These lines CLOSE our files and set the counters back to zero. The program proceeds to the NEXT high and low values and runs the entire cycle again. It will continue until both counters reach 27. Then program then closes the file and jumps to END.
CLOSE #2
CLOSE #1: HIT = 0: R1 = 0: I = 0: MISS = 0
520 NEXT Z
522 NEXT Y
525 IF Y > 27 THEN 550 <---This is another artifact leftover from rewrite 11734.
550 CLOSE #1: END
Okay. I'm through with anal for the day.