Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need quick help with a small project
#1
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?
Reply
#2
Store them in an array just like you do with the names.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
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.
Reply
#4
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
Reply
#5
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
Reply
#6
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
Reply
#7
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
Reply
#8
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
Reply
#9
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"
Reply
#10
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)