2

I am taking a computer sciences class right now, and I just have no idea how to convert an average made from 3 scores to a letter grade. At first I thought I could do something like:

PRINT name$(c); TAB(6) ; USING("###.#", average(c))

As:

PRINT name$(c); TAB(6) ; USING("***something for text here***", average(c))

But after my searches and scouring on the internet, I came up with nothing. After a while I rewrote a majority of my code, but it still doesnt work correctly. Can someone tell me what I can do to get it working?

Here it is:

dim names(20)
dim average$(20)
x = 0
input "Please input Teacher's name:"; teacher$
rem teacher$
cls
input "Input student's name:"; studentname$
do while studentname$ <> ""
name$(x)=studentname$
rem name$(x)
input "Input first number:"; e
input "Input second number:"; f
input "Input third number:"; g
avg$=(e+f+g)/3
average(x)= avg
x=x+1
cls
input "Input the next name or press enter to finish:"; studentname$
loop
print teacher$; "'s Class Report"
for c = 1 to X
if (avg$>89 and avg$<101) then let avg= "A" else if
if (avg$>79 and avg$<89) then let avg= "B" else if
if (avg$>69 and avg$<79) then let avg= "C" else if
if (avg$>59 and avg$<69) then let avg= "D" else if
if (avg$<59) then let avg= "F"; print names(c), TAB(6) average$(c)
next c
end
GSerg
  • 76,472
  • 17
  • 159
  • 346
  • You calculate the letter based on `avg` and then output `average$(c)`. Do the opposite. – GSerg Oct 14 '15 at 22:49
  • 1
    And it is easy to get confused, so its good practice to make your variable names distinct. You might have gotten mixed up between `avg` and `average`. You could refactor it to be `class_averages` perhaps, to make it easier to remember. – Shawn Mehan Oct 15 '15 at 00:11

3 Answers3

0

Three thing to note here.

First off, the dollar sign $ is only used at the end of variablenames that contain text values not numeric values. So it's a$ = "hello" and i = (12+34+56) / 3 etc.

Secondly, in the input part you calculate the average value and store it in variable avg$. Then in the for-loop where you want to print the letter grades you check the same variable name. However, you never set avg$ within that for-loop, so it will always just contain the last calculated value. And also it should be without $ because it's a numeric value.

Finally, like Shawn Mehan also already commented, you should rename your variables to better reflect what they are used for. That will probably clear up some of the confusion. So something like dim avgpoint(20) for the 0-100 scores, and avgletter$="A" etc. for the letters grade.

So to combine these things, I would change your code to something like this:

input "Input first grade number (0-100):"; grade1
input "Input second grade number (0-100):"; grade2
input "Input third grade number (0-100):"; grade3
calcavg = (grade1+grade2+grade3)/3
avgpoint(x) = calcavg

and then

for c = 1 to x
    p = avgpoint(x)
    if (p>89 and p<=101) then let avgletter$ = "A"
    'etc.
BdR
  • 2,770
  • 2
  • 17
  • 36
0

Here is some coding sample for a grade report program:

DIM Names(20) AS STRING
DIM Average(20) AS SINGLE
INPUT "Please input Teacher's name"; Teacher$
PRINT "Enter up to 20 names, <enter> to quit:"
DO UNTIL x = 20
    PRINT "Input student"; x + 1; "name";
    INPUT StudentName$
    IF StudentName$ = "" THEN EXIT DO
    x = x + 1: Names(x) = StudentName$
    INPUT "Input first number"; J
    INPUT "Input second number"; K
    INPUT "Input third number"; L
    Average(x) = (J + K + L) / 3
LOOP
PRINT Teacher$; "'s Class Report"
FOR c = 1 TO x
    SELECT CASE Average(c)
        CASE 0 TO 59
            Grade$ = "F"
        CASE 60 TO 69
            Grade$ = "D"
        CASE 70 TO 79
            Grade$ = "C"
        CASE 80 TO 89
            Grade$ = "B"
        CASE ELSE
            Grade$ = "A"
    END SELECT
    PRINT Names(c); SPC(6); Grade$
NEXT
END
eoredson
  • 1,167
  • 2
  • 14
  • 29
0

Another coding sample of a grade report program with variable number of scores:

DIM Names(20) AS STRING
DIM Average(20) AS SINGLE
INPUT "Please input Teacher's name"; Teacher$
PRINT "Enter up to 20 names, <enter> to quit:"
DO UNTIL x = 20
    PRINT "Input student"; x + 1; "name";
    INPUT StudentName$
    IF StudentName$ = "" THEN EXIT DO
    x = x + 1: Names(x) = StudentName$
    y = 0 ' number of scores
    z = 0 ' total of scores
    PRINT "Enter scores, <enter> to quit:"
    DO
        PRINT "Enter score"; y + 1;
        INPUT I$
        IF I$ = "" THEN EXIT DO
        IF VAL(I$) >= 0 AND VAL(I$) <= 100 THEN
            y = y + 1
            z = z + VAL(I$)
        ELSE
            PRINT "Value must be 0 to 100."
        END IF
    LOOP
    IF y > 0 THEN ' avoid division by zero
        Average(x) = z / y
    END IF
LOOP
PRINT Teacher$; "'s Class Report"
FOR c = 1 TO x
    SELECT CASE Average(c)
        CASE 0 TO 59
            Grade$ = "F"
        CASE 60 TO 69
            Grade$ = "D"
        CASE 70 TO 79
            Grade$ = "C"
        CASE 80 TO 89
            Grade$ = "B"
        CASE ELSE
            Grade$ = "A"
    END SELECT
    PRINT Names(c); SPC(6); Grade$
NEXT
END
eoredson
  • 1,167
  • 2
  • 14
  • 29