PRINT "The average is", SUM/15 ' Print out the average
Often the first number in a file says how many numbers follow. For example, The first number in the following says how many data values there are:
7 47.5 49.8 50.2 49.3 48.0 47.1 48.9
Say that the file contains the prices of a stock for several days in a row. The first number (in line one of the file) says how many stock prices follow it. As more data is gathered, it could easily be added at the end of the file and the first number would be changed. Here is a program that computes the average stock price:
OPEN "STOCKS.DAT" FOR INPUT AS #3 INPUT #3, DAYS LET SUM = 0 LET COUNT = 1 DO WHILE COUNT <= DAYS INPUT #3, NUM LET SUM = SUM + NUM LET COUNT = COUNT + 1 LOOP PRINT "Average Price is", SUM/DAYS END
Can programs do input of text?