|
Post by maynardjrm on Jun 19, 2002 22:23:17 GMT
I am trying to write a program to average scores. I want to enter a list of scores and get an average once I am done. Any help would be appreciated
|
|
|
Post by brisray on Jun 20, 2002 1:29:59 GMT
All an average is is a total of several elements divided by the number of elements.
To do this you may be better off using an array. A very simple piece of code to calculate the average of 5 numbers would be
FOR Count = 1 TO 5 PRINT "Score #"; Count PRINT INPUT "What is this score? ", MyArray(Count) PRINT AveScore = AveScore + MyArray(Count) NEXT Count
AveScore = AveScore / 5 PRINT PRINT "The average score is"; AveScore
The code won't win you any prizes and you'll probably need to edit it to get it to work for the number of variables you want, but it should give you an idea of how to do it.
Ray
|
|
|
Post by programmer on Jun 21, 2002 3:23:06 GMT
i have made my own averager already witch i would like to send to u but to save time here is my source code(so poorly made ): TOP: PRINT "ENTER THE NUMBER OF DATA YOU WANT TO AVERAGE THEN ENTER THAT NUMBER OF DATA PRINT "SEPERATED BY COMMAS(ONLY GOES UP TO TEN CAUSE IM TO LAZY TO MAKE IT MORE" INPUT Q IF Q = 2 THEN GOTO TWO IF Q = 3 THEN GOTO THREE IF Q = 4 THEN GOTO FOUR IF Q = 5 THEN GOTO FIVE IF Q = 6 THEN GOTO SIX IF Q = 7 THEN GOTO SEVEN IF Q = 8 THEN GOTO EIGHT IF Q = 9 THEN GOTO NINE IF Q = 10 THEN GOTO TEN TWO: INPUT Q, W PRINT "THE AVERAGE IS"; (Q + W) / 2 GOTO TOP THREE: PRINT "THE AVERAGE IS"; (Q + W + E) / 3 GOTO TOP FOUR: INPUT Q, W, E, R PRINT "THE AVERAGE IS"; (Q + W + E + R) / 4 GOTO TOP FIVE: INPUT Q, W, E, R, T PRINT "THE AVERAGE IS"; (Q + W + E + R + T) / 5 GOTO TOP SIX: INPUT Q, W, E, R, T, Y PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y) / 6 GOTO TOP SEVEN: INPUT Q, W, E, R, T, Y, U PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y + U) / 7 GOTO TOP EIGHT: INPUT Q, W, E, R, T, Y, U, I PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y + U + O) / 8 GOTO TOP NINE: INPUT Q, W, E, R, T, Y, U, I, O PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y + U + O) / 9 GOTO TOP TEN: INPUT Q, W, E, R, T, Y, U, I, O, P PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y + U + O + P) / 10 GOTO TOP
|
|
|
Post by programmer on Jun 21, 2002 3:31:41 GMT
i have made my own averager already witch i would like to send to u but to save time here is my source code(so poorly made ): TOP: PRINT "ENTER THE NUMBER OF DATA YOU WANT TO AVERAGE THEN ENTER THAT NUMBER OF DATA PRINT "SEPERATED BY COMMAS(ONLY GOES UP TO TEN CAUSE IM TO LAZY TO MAKE IT MORE" INPUT Q IF Q = 2 THEN GOTO TWO IF Q = 3 THEN GOTO THREE IF Q = 4 THEN GOTO FOUR IF Q = 5 THEN GOTO FIVE IF Q = 6 THEN GOTO SIX IF Q = 7 THEN GOTO SEVEN IF Q = 8 THEN GOTO EIGHT IF Q = 9 THEN GOTO NINE IF Q = 10 THEN GOTO TEN TWO: INPUT Q, W PRINT "THE AVERAGE IS"; (Q + W) / 2 GOTO TOP THREE: PRINT "THE AVERAGE IS"; (Q + W + E) / 3 GOTO TOP FOUR: INPUT Q, W, E, R PRINT "THE AVERAGE IS"; (Q + W + E + R) / 4 GOTO TOP FIVE: INPUT Q, W, E, R, T PRINT "THE AVERAGE IS"; (Q + W + E + R + T) / 5 GOTO TOP SIX: INPUT Q, W, E, R, T, Y PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y) / 6 GOTO TOP SEVEN: INPUT Q, W, E, R, T, Y, U PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y + U) / 7 GOTO TOP EIGHT: INPUT Q, W, E, R, T, Y, U, I PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y + U + O) / 8 GOTO TOP NINE: INPUT Q, W, E, R, T, Y, U, I, O PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y + U + O + I) / 9 GOTO TOP TEN: INPUT Q, W, E, R, T, Y, U, I, O, P PRINT "THE AVERAGE IS"; (Q + W + E + R + T + Y + U + O + I + P) / 10 GOTO TOP jus copy/paste that
|
|
Ziggi
Full Member
Posts: 87
|
Post by Ziggi on Jun 21, 2002 7:28:53 GMT
Hey Programmer.First thing don't repeat your self, and the second thing all good programmers want to create programs as short as possible, I thing that the example by brisray is the best. The number five in the loop can be also inputted as a variable so the loop always can be different.
|
|
|
Post by programmer on Jun 22, 2002 14:15:31 GMT
yes yes i no. i should quote in the 2 post "(so poorly made )" and about repeatin my self if u look carefully at the source code youll see i dont have enough vaibles in the last section. and im one month in to programin(i no its plenty of time to learn but im pitiful like that-ex: i have an exscuse for everything)
|
|
Ziggi
Full Member
Posts: 87
|
Post by Ziggi on Jun 23, 2002 3:35:29 GMT
Well if you realy want to input numbers seperated by commas and you don't want to run out of variables then here is program for you:
CLS LINE INPUT "Input DATA for average seperate by commas : "; A$ OPEN "C:\test.txt" FOR OUTPUT AS 1 PRINT #1, A$ CLOSE 1 counter = 0 OPEN "C:\test.txt" FOR INPUT AS 1 DO WHILE NOT EOF(1) INPUT #1, number counter = counter + 1 B = B + number LOOP CLOSE 1
PRINT : PRINT : PRINT PRINT "Average of numbers "; A$; " ="; B / counter
|
|