Trying to get void getscore() to read from a file Please help!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Diablo01
    New Member
    • Jun 2014
    • 13

    Trying to get void getscore() to read from a file Please help!

    #include <iostream>
    #include <iomanip>
    #include <fstream>
    using namespace std;

    // Function prototype
    void getScore(int &);
    void calcAverage(int , int, int, int, int);
    int findLowest(int, int, int, int, int);
    int grades(int, int, int, int, int);
    int main()
    {
    ifstream grades;
    grades.open("gr ades.txt");

    int testScr1, testScr2, testScr3, testScr4, testScr5;


    getScore(testSc r1);
    getScore(testSc r2);
    getScore(testSc r3);
    getScore(testSc r4);
    getScore(testSc r5);

    calcAverage(tes tScr1, testScr2, testScr3, testScr4, testScr5);

    return 0;
    }

    void getScore(int &score)
    {



    }

    void calcAverage(int s1, int s2, int s3, int s4, int s5)
    {
    int sum;
    int lowest;
    double average;


    lowest = findLowest(s1, s2, s3, s4, s5);

    sum = s1 + s2 + s3 + s4 + s5 - lowest;
    average = sum / 4.0;

    cout << setw(4) << fixed << showpoint << setprecision(2) ;
    cout << "The avergae of the four highest scores are: " << average << endl;
    }

    int findLowest(int s1, int s2, int s3, int s4, int s5)
    {
    int lowest = s1;

    cout << "The lowest test score is: " << lowest << endl;

    return lowest;
    }
    it is not reading from the file and returning required info. Please help!
  • Diablo01
    New Member
    • Jun 2014
    • 13

    #2
    This is the problem I cant figure out....void getscore() should read a score from a file and store it in reference parameter variable. This function should be called on for each of the 5 scores to be entered.

    Comment

    • divideby0
      New Member
      • May 2012
      • 131

      #3
      getScore() needs access to your input file. since you've created the fstream object in main, you could modify getScore's parameter list to take "grades" as a second argument.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Be sure the file argument is by reference to avoid making a copy. Otherwise you won't be using the file you opened.

        Comment

        Working...