calculating the average of five different numbers - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

calculating the average of five different numbers

mikee_66mikee_66 Posts: 1Member
I need some help getting my program(QBasic) to work right for me. My project is to simply write a program that inputs name, age, and 5 test scores. If the person's age is not 25 or older, then a message should say that the student is underage. I need the program to calculate the 5 scores and give me the average, and then tell me the different letter grades A,B,C,D, and if the average is below a 70%, then i need for a message to say that the student did not pass. I am stuck, someone with more knowledge please help, i would be most appreciative.....

Comments

  • WaltPWaltP Posts: 335Member
    : I need some help getting my program(QBasic) to work right for me. My project is to simply write a program that inputs name, age, and 5 test scores. If the person's age is not 25 or older, then a message should say that the student is underage. I need the program to calculate the 5 scores and give me the average, and then tell me the different letter grades A,B,C,D, and if the average is below a 70%, then i need for a message to say that the student did not pass. I am stuck, someone with more knowledge please help, i would be most appreciative.....
    :
    Start with the easy stuff first
    10 print "Enter Person's Name";
    20 input pname$
    30 print pname$
    40 end

    Continue from there

    ----------------
    Walt


  • Folker FritzFolker Fritz Posts: 19Member
    I don't know if I have understand correctly what you are looking for, but here is a very easy code for what I think that you need.



    DEFINT A-Z
    number.of.results = 5 'increase if more results
    DIM grades(number.of.results)
    CLS
    INPUT "Name: ", name$
    INPUT "Age: ", age
    IF age < 25 THEN PRINT "You are too jung!": END 'person under 25?
    FOR temp = 1 TO number.of.results 'ask for results
    PRINT "Insert grade score" + STR$(temp)
    INPUT grade.score$
    SELECT CASE grade.score$
    CASE "A", "a", "1": grades(temp) = 1
    CASE "B", "b", "2": grades(temp) = 2
    CASE "C", "c", "3": grades(temp) = 3
    CASE "D", "d", "4": grades(temp) = 4
    CASE "E", "e", "5": grades(temp) = 5
    CASE "F", "f", "6": grades(temp) = 6
    CASE ELSE 'wrong answer, then ask again
    temp = temp - 1
    END SELECT
    NEXT
    FOR temp = 1 TO number.of.results
    result = result + grades(temp)
    NEXT
    IF result > 6 / 100 * 30 THEN '100% - 70% (70% needed) = 30, so * 30
    PRINT "Average under 70%!"
    ELSE
    PRINT "Average over 70%!"
    END IF
    END
  • tlmcduffietlmcduffie Posts: 9Member
    [b][red]This message was edited by tlmcduffie at 2003-9-20 12:33:22[/red][/b][hr]
    : I need some help getting my program(QBasic) to work right for me. My project is to simply write a program that inputs name, age, and 5 test scores. If the person's age is not 25 or older, then a message should say that the student is underage. I need the program to calculate the 5 scores and give me the average, and then tell me the different letter grades A,B,C,D, and if the average is below a 70%, then i need for a message to say that the student did not pass. I am stuck, someone with more knowledge please help, i would be most appreciative.....
    :

    Try copy/pasting this program and running it.

    It will start by asking for 4 parameters. These are:

    A grade (1-100) you consider to be the lowest A,B,C and D. Based on this, it gives the grades A thru F to the tests and the average. An average below 70% can be failing (like you asked) but you would have to tell it that the lowest "D" would be 70. This should give you some flexibility. Hope this helps, and GOOD LUCK!!



    dim grade(5), lowGrade(4), testName$(5), seq$(5)
    seq$(1)="first "
    seq$(2)="second"
    seq$(3)="third "
    seq$(4)="fourth"
    seq$(5)="fifth "
    grLetter$="ABCD"

    begin:
    color 7,0
    cls
    print "Test averaging program"
    print "======================"
    print
    print "Lets enter some basic info before we get started .."
    print
    for ix%=1 to 4

    print "enter a number (1-100) that you consider to be the lowest ";mid$(grLetter$,ix%,1);
    input lowGrade(ix%)
    print string$(78,"-")

    next ix%

    enterTests:
    color 7,0
    cls
    line input "Enter student name or / to end program: ";name$
    if name$="/" then
    cls
    end
    end if

    line input "Enter student age : ";age$
    age%=val(age$)
    print string$(78,"=")
    for ix%=1 to 5
    print "Enter the subject name for the ";seq$(ix%);" test: ";
    line input testName$(ix%)
    line input "Enter the grade for this test (1-100): ";grade$
    grade(ix%)=val(grade$)
    print string$(78,"-")
    next ix%

    cls

    displayReport:
    color 7,0
    cls
    gosub computeAverage
    print "Test Average Report for ";name$
    print
    print "Age is ";age$

    if (age%=>25)=0 then
    color 6,0
    print " ** Student is underage **"
    end if

    color 7,0

    stuGrade=average
    gosub determineAthruF
    print "Test average is";
    print using "###.##";average
    print "This is a grade of ";grade$
    if grade$="F" then
    color 4,0
    print "** Student did not pass **"
    end if
    color 7,0
    print
    print "Test Summary (those in ";
    color 4,0
    print "red";
    color 7,0
    print " are failing)"
    print
    for ix%=1 to 5
    color 7,0
    stuGrade=grade(ix%)
    gosub determineAthruF
    rptName$=space$(25)
    mid$(rptName$,1)=testName$(ix%)
    if grade$="F" then
    color 4,0
    end if
    print rptName$,grade$,
    print using "###.##";stuGrade
    next ix%
    color 7,0
    print
    line input "Do you wish to average another student (Y/N) ";yn$
    yn$=ucase$(yn$)
    if yn$="Y" then
    goto enterTests
    end if
    end

    computeAverage:

    total=0
    for ix%=1 to 5
    total=total+grade(ix%)
    next ix%
    average=total/5
    return

    determineAthruF:
    if stuGrade=>lowGrade(4) then
    grade$="D"
    if stuGrade=>lowGrade(3) then
    grade$="C"
    if stugrade=>lowGrade(2) then
    grade$="B"
    if stuGrade=>lowGrade(1) then
    grade$="A"
    end if
    end if
    end if
    else
    grade$="F"
    end if
    return


Sign In or Register to comment.