Small problem in a small program

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!
Post Reply
Nexgen
Newbie
Posts: 1
Joined: Sun Dec 12, 2010 4:50 pm
Location: Alba-Romania

Small problem in a small program

Post by Nexgen »

Why does work the code below, the compiler tell me it`s a problem whit array n(i). I really can not see the problem.
I usigng QB64.

Code: Select all

DIM num AS STRING
DIM nrnot AS INTEGER
DIM n(i) AS INTEGER
DIM sum AS INTEGER
INPUT "Numele: "; num
PRINT "Nr de note pentru studentul "; num; ":";
INPUT nrnot
FOR i = 1 TO nrnot
    IF i = 1 THEN
        PRINT "Introdu prima nota: "
        INPUT n(i)
    ELSE
        PRINT "Introdu a- "; i; "-a nota:"
        INPUT n(i)
    END IF

    sum = sum + n(i)

NEXT i
med = sum / nrnot
PRINT "Media este:"
IF med < 5 THEN
    COLOR 4
    PRINT med
ELSEIF med = 5 THEN
    COLOR 2
    PRINT med
ELSE
    COLOR 1
    PRINT med

END IF
COLOR 0
Sorry for my english!
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

i = 0 when the program starts so you are making an array with 0 elements. Put the number of the elements the program will need in there.

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply