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

  • SEARCH
  • Home
  • 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 6921699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:18:37+00:00 2026-05-27T10:18:37+00:00

I am getting this error when I run the program. It compiles successfully but

  • 0

I am getting this error when I run the program. It compiles successfully but gives me a few warnings about the uninitialized variables which, I thought are initialized. I get the error “Debug error! Run-Time Check Failure #3- The variable ‘sumMaleGPA’ is being used without being initialized.”

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

using namespace std;

void 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;
}
void sumGrades(ifstream& inFile, float sumFemaleGPA, float sumMaleGPA,int m,int f)
{
sumFemaleGPA=0;
sumMaleGPA=0;

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

while(!inFile.eof())
{

    inFile >> sex >> grade;

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

avgfGPA=sumFemaleGPA/f;
avgmGPA=sumMaleGPA/m;
}

void 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);


}

Not sure where the error is happening so I posted the entire file.

  • 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-27T10:18:37+00:00Added an answer on May 27, 2026 at 10:18 am

    Your initialize and averageGPA functions are not correct.

    Any parameter you want to modify inside the function should be passed by reference:

    void initialize(int &countFemale,int &countMale,float &sumFemaleGPA,float &sumMaleGPA)
    void averageGPA(float &avgfGPA, float &avgmGPA, int m, int f, float &sumFemaleGPA, float &sumMaleGPA)
    

    As it is, the initialize() function doesn’t actually initialize the variables – hence why the you get the debug error when you first try to use them.

    Right now, you are passing by value. The parameters are copied into the function. The function then modifies the local copies instead of the ones that are passed in.

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

Sidebar

Related Questions

I am getting this error while running a hadoop pipes program. The program compiles
I keep getting this error when I run the program. Object reference not set
I am getting this error when I run my program and I have no
I keep getting this error when I run my web app (asp.net mvc) in
I am getting this error when trying to run internet information services on a
A buddy of mine has been getting this error mesage when trying to run
I am getting this run time error when using IID_IWebBrowser2 interface of CLSID_InternetExplorer. Run-Time
I am getting an error when I run this query because the data type
I'm getting a strange syntax error when I run this in VB: SQLString =
I successfully compiled my OpenGL program in MSVC 2008, But I am getting a

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.