Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:28:50+00:00 2026-05-27T09:28:50+00:00

I cannot seem to spot the error here, other articles are a bit fuzzy

  • 0

I cannot seem to spot the error here, other articles are a bit fuzzy about the answers to the error so here is mine. I am getting this error, I believe it has something to do with the files it is trying to open. I posted the entire .cpp file as I am not sure where the error stems from.

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

int openFiles(ifstream inFile, ofstream outFile)
{
inFile.open("finalin.dat");
outFile.open("finalout.dat");
outFile << fixed << showpoint << setprecision(2);
inFile >> fixed >> showpoint >> setprecision(2);
if (!inFile||!outFile)
{
    cout << "Problem opening file.";
}
}
void initialize(int countFemale,int countMale,float sumFemaleGPA,float sumMaleGPA)
{
countFemale=0;
countMale=0;
sumFemaleGPA=0;
sumMaleGPA=0;
}
int sumGrades(ifstream inFile, float sumFemaleGPA, float sumMaleGPA,int m,int f)
{

    if (!inFile)
    {
        inFile.open("finalin.dat");
    }
char sex;
float grade;    

while(!inFile.eof())
{

    inFile >> sex >> grade;

    switch (sex)
    {
    case 'f': (sumFemaleGPA + grade);
         f++;
        break;
    case 'm': (sumMaleGPA + grade);
            m++; 
         break;
    }
}
}
int averageGPA(float avgfGPA, float avgmGPA, int m, int f, float sumFemaleGPA,   float sumMaleGPA)
{
avgfGPA=sumFemaleGPA/f;
avgmGPA=sumMaleGPA/m;
}

int printResults(float avgfGPA, float avgmGPA, ofstream outFile)
{
        cout <<"The average GPA of the female students is: "<<  avgfGPA << endl;
        cout <<"The average GPA of the male students is: "<< avgmGPA;

        outFile << "The average GPA of the female students is: "<<  avgfGPA << endl;
        outFile <<"The average GPA of the male students is: "<< avgmGPA;

}

        int main()
{

int countFemale;
int countMale;
float sumFemaleGPA;
float sumMaleGPA;
float avgfGPA; 
float avgmGPA;

ifstream inFile;
ofstream outFile;

openFiles(inFile,outFile);
initialize(countFemale,countMale,sumFemaleGPA,sumMaleGPA);
sumGrades(inFile,sumFemaleGPA,sumMaleGPA,countMale,countFemale);
averageGPA(avgfGPA,avgmGPA,countMale,countFemale,sumFemaleGPA,sumMaleGPA);
printResults(avgfGPA,avgmGPA, outFile);


}

Also, I realize that having 5 functions like that is a bit messy, but that is how our professor requested it since we are to demonstrate our knowledge of functions as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:28:50+00:00Added an answer on May 27, 2026 at 9:28 am

    The problem is that you cannot pass streams by value, you have to pass them by reference or pointer. in every function arguments definition add & after streams like:

    int printResults(float avgfGPA, float avgmGPA, ofstream& outFile)
    

    instead of

    int printResults(float avgfGPA, float avgmGPA, ofstream outFile)
    

    Edit:
    Your initialize doesn’t do anything because it takes arguments by value. you need to take them by reference to be able to modify the source, use

    void initialize(int &countFemale,int &countMale,float &sumFemaleGPA,float &sumMaleGPA)
    

    instead of

    void initialize(int countFemale,int countMale,float sumFemaleGPA,float sumMaleGPA)
    

    and the warning should go away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot seem to get how this is done. I've read a bit about
I cannot seem to figure out I am getting the following error in IE
I cannot seem to find any concrete answers for this. I have a client
I cannot seem to compile mod_dontdothat on Windows. Has anybody managed to achieve this?
i cannot seem to find the answer to this. i uploaded code to pastebin
I am getting very frustrated because I cannot seem to figure out why Collections
I have this design which I cannot seem to get right, I would like
I've been searching around for this and cannot seem to find a solid answer.
I know this may be basic but I cannot seem to add a member
I was given the script found here http://jsfiddle.net/b2Nq9/2/ but cannot get it to seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.