grade average using c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RALPH2133
    New Member
    • Oct 2007
    • 1

    grade average using c++

    hi guys
    i new in this section
    i have a doubt;
    im trying to find the student average on my execise,here a copy

    [CODE=cpp]#include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;

    int main(int argc, char *argv[])
    {
    ifstream infile;
    ofstream outfile;
    infile.open("fi lein.dat");
    outfile.open("o utrep.txt");

    outfile << "\t\t\t TURABO UNIVERSITY" << endl;
    outfile << "\t\t\tGRAD E AVERAGE\n" << endl;
    outfile << "\tSTUDENT" << "\t\tFIRST" << "\t\tSECOND " << "\t\tTHIRD" << "\t\tSTUDEN T" << endl;
    outfile << "\tNUMBER" << "\t\tExam" << "\t\tExam" << "\t\tExam" << "\t\tAVERAG E" << endl;


    while (infile)
    string sn;
    int sn;
    int fe=00;
    int se=00;
    int te=00;
    int st=00;
    float avr=00.0;
    float cavr=00;

    sn=458;
    fe=90;
    se=85;
    te=75;
    avr=fe+se+te/3;
    cavr=cavr+avr;
    outfile << "\t" << sn << "\t\t" << fe << "\t\t" << se << "\t\t" << te << endl;

    sn=459;
    fe=100;
    se=88;
    te=78;
    avr=fe+se+te/3;
    cavr=cavr+avr;
    outfile << "\t" << sn << "\t\t" << fe << "\t\t" << se << "\t\t" << te << endl;

    sn=4510;
    fe=67;
    se=90;
    te=99;
    avr=fe+se+te/3;
    outfile << "\t" << sn << "\t\t" << fe << "\t\t" << se << "\t\t" << te << endl;


    st=st+3;

    cavr=cavr+avr;


    outfile << "\tSTUDENT TOTAL: " << st << endl << endl;

    outfile << "\tCLASS AVERAGE: " << cavr << endl << endl;

    system("PAUSE") ;
    return EXIT_SUCCESS;[/CODE]
    Last edited by Ganon11; Oct 3 '07, 10:31 PM. Reason: Please use the [CODE] tags provided.
  • kaioshin00
    New Member
    • Nov 2006
    • 46

    #2
    Originally posted by RALPH2133
    hi guys
    i new in this section
    i have a doubt;
    im trying to find the student average on my execise,here a copy

    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;

    int main(int argc, char *argv[])
    {
    ifstream infile;
    ofstream outfile;
    infile.open("fi lein.dat");
    outfile.open("o utrep.txt");

    outfile << "\t\t\t TURABO UNIVERSITY" << endl;
    outfile << "\t\t\tGRAD E AVERAGE\n" << endl;
    outfile << "\tSTUDENT" << "\t\tFIRST" << "\t\tSECOND " << "\t\tTHIRD" << "\t\tSTUDEN T" << endl;
    outfile << "\tNUMBER" << "\t\tExam" << "\t\tExam" << "\t\tExam" << "\t\tAVERAG E" << endl;


    while (infile)
    string sn;
    int sn;
    int fe=00;
    int se=00;
    int te=00;
    int st=00;
    float avr=00.0;
    float cavr=00;

    sn=458;
    fe=90;
    se=85;
    te=75;
    avr=fe+se+te/3;
    cavr=cavr+avr;
    outfile << "\t" << sn << "\t\t" << fe << "\t\t" << se << "\t\t" << te << endl;

    sn=459;
    fe=100;
    se=88;
    te=78;
    avr=fe+se+te/3;
    cavr=cavr+avr;
    outfile << "\t" << sn << "\t\t" << fe << "\t\t" << se << "\t\t" << te << endl;

    sn=4510;
    fe=67;
    se=90;
    te=99;
    avr=fe+se+te/3;
    outfile << "\t" << sn << "\t\t" << fe << "\t\t" << se << "\t\t" << te << endl;


    st=st+3;

    cavr=cavr+avr;


    outfile << "\tSTUDENT TOTAL: " << st << endl << endl;

    outfile << "\tCLASS AVERAGE: " << cavr << endl << endl;

    system("PAUSE") ;
    return EXIT_SUCCESS;

    I'm not sure what exactly all your variables stand for and what they're doing, but I did notice this:

    Code:
    avr=fe+se+te/3;
    Multiplication and division have a higher preference than addition or subtraction, so this would divide te by 3, and then add fe and se to that.

    I'm guessing avr means average, so you should probably try:

    Code:
    avr = (fe+se+te)/3;

    Comment

    Working...