Posts: 13
Threads: 2
Joined: Dec 2003
here is a project i have to do
CLS
PRINT "how many students are there?"
INPUT num
DIM student$(num)
FOR q = 1 TO num
PRINT "enter name"
INPUT student$(q)
PRINT "Enter marks"
INPUT a
INPUT b
INPUT c
INPUT d
INPUT e
NEXT
FOR q = 1 TO num
w = a + b + c + d + e
NEXT
FOR q = 1 TO num
PRINT student$(q); w / 5
IF w / 5 < 50 THEN
PRINT "Fail"
ELSE
PRINT "Passed"
END IF
NEXT
i need help with printing the average (w/5)
because it only prints the average of the last person but i need it to show the average of each person
can you help me?
Posts: 6,419
Threads: 74
Joined: Mar 2002
Store them in an array just like you do with the names.
Posts: 3,368
Threads: 195
Joined: Jan 2003
a, b, c, d, and e need to be arrays, just like your name array, if you want to do that.
Better yet:
Code:
DIM score(1 TO num, 5)
'...............
FOR i% = 1 TO num
avg = 0
FOR j% = 1 TO 5
avg = avg + score(i%, j%)
NEXT j%
PRINT avg / 5
NEXT i%
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 109
Threads: 17
Joined: Mar 2003
Do it more like this
Code:
CLS
PRINT "how many students are there?"
INPUT num
DIM student$(num)
FOR q = 1 TO num
PRINT "enter name"
INPUT student$(q)
PRINT "Enter marks"
INPUT a
INPUT b
INPUT c
INPUT d
INPUT e
PRINT student$(q); ": "; (a + b + c + d + e ) /5
IF (a + b + c + d + e) / 5 < 50 THEN
PRINT "Fail"
ELSE
PRINT "Passed"
END IF
NEXT
Posts: 13
Threads: 2
Joined: Dec 2003
i tried dan the man's idea but it good and all but the average and names ,etc have to be listed after everything has been inputted
Posts: 13
Threads: 2
Joined: Dec 2003
Quote:Do it more like this
Code:
CLS
PRINT "how many students are there?"
INPUT num
DIM student$(num)
FOR q = 1 TO num
PRINT "enter name"
INPUT student$(q)
PRINT "Enter marks"
INPUT a
INPUT b
INPUT c
INPUT d
INPUT e
PRINT student$(q); ": "; (a + b + c + d + e ) /5
IF (a + b + c + d + e) / 5 < 50 THEN
PRINT "Fail"
ELSE
PRINT "Passed"
END IF
NEXT
i changed it a bit to this:
CLS
PRINT "how many students are there?"
INPUT num
DIM student$(num)
FOR q = 1 TO num
PRINT "enter name"
INPUT student$(q)
PRINT "Enter marks"
INPUT a
INPUT b
INPUT c
INPUT d
INPUT e
PRINT student$(q); "'s average is"; (a + b + c + d + e) / 5
IF (a + b + c + d + e) / 5 < 50 THEN
PRINT student$(q); " has Failed"
ELSE
PRINT student$(q); " has Passed"
COLOR 4
PRINT "Congratulations!!"
COLOR 15
END IF
NEXT
but i need the student and their average to be displayed at the end
Posts: 109
Threads: 17
Joined: Mar 2003
then make an array. or, better yet, use typing
Code:
Type student
Name as string
a as integer
b as int
...ect...
end type
.....
dim Student(num) as student
.......
input student(q).a
......
student(q).w = student(q).a+student(q).b + ect...
ect.....
you get the point
Posts: 13
Threads: 2
Joined: Dec 2003
sorry
i'm a beginner
so i don't really kno how to do this :???:
what is typing?
i haven't learned that yet.
i must sound really dumb
Posts: 109
Threads: 17
Joined: Mar 2003
not at all. we were all beginners. i'm not too good at programming anyway. you can make special variable types using typing. it's making new dimensions to enter data. you can use it by doing a "type variable name" command, followed by the subvariables and their types, ex "a as integer", "name as string".
then you end it by the "end type" command.
you then have to dim a var in that type. "dim var name as type name" you can dim arrays in that fasion too.
to call a typed var, use "var name . subvariable"
Posts: 13
Threads: 2
Joined: Dec 2003
wow i'm totally stumped
i made it so that the info is printed at the end
but the average is messing up
CLS
PRINT "how many students are there?"
INPUT num
DIM student$(num)
FOR q = 1 TO num
PRINT "enter name"
INPUT student$(q)
PRINT "Enter marks"
INPUT a
INPUT b
INPUT c
INPUT d
INPUT e
NEXT
FOR q = 1 TO num
PRINT student$(q); "'s average is"; (a + b + c + d + e) / 5
IF (a + b + c + d + e) / 5 < 50 THEN
PRINT student$(q); " has Failed"
ELSE
PRINT student$(q); " has Passed"
COLOR 4
PRINT "Congratulations!!"
COLOR 15
END IF
NEXT
the average prints as the last persons average