You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
There's many ways for doing this, but if you want to see the average as you enter them, you might try something like this:
Code:
#COMPILE EXE
FUNCTION PBMAIN () AS LONG
LOCAL Grading AS STRING, Grades AS LONG, nbr AS LONG
WHILE Grading <> "end"
INCR nbr
LOCATE 8, 39 : PRINT SPACE$(10)
LOCATE 8, 10 : LINE INPUT "Enter a Grade or end to quit "; Grading
Grades = Grades + VAL(Grading)
LOCATE 10, 10 : PRINT "The Average grade for "; nbr; " Entries is "; Grades\nbr
WEND
END FUNCTION
Set it up that the user enters grades seperated by whatever delimiter you specify, then [ENTER] at the end of line when done. Then use ParseCount and Parse to take it all apart, divide by the # delimiters, etc.
Basically you write these kinds of programs by prompting for grades, and ending when some special value is entered. eg in PB/CC you might write
Code:
LOCAL Grade$
LOCAL nGrade AS LONG, iGrade AS LONG, tGrade AS LONG
DO
LINE INPUT "Grade", Grade$
IF Grade = "END" THEN
PRINT USING$ ( # grades averaging ##.## processed.", ngrade, tGrade/nGrade)
EXIT DO
ELSE
INCR nGrade
iGrade = VAL (Grade$)
tGrade = tGrade + iGrade
PRINT USING$("#, grades processed so far", nGrade)
END IF
LOOP
i am writing a grade cal. i have written the code to take five grade inputed by the user and / then by 5. how do i get unlitemed inputs and then / by that #.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: