input/output text files C++ need of saving

I dont know what i am doing wrong in this code because my answers on my output statement keep coming out wrong. In my input file I have each number a space away from each other. The result keeps coming out tiny and negative. Im brand new to c++ and i dont know what im doing wrong.
Thanks!!

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>


using namespace std;
int main()
{
ofstream outFile;
ifstream dataFile;
double score1, score2, score3, score4, score5;
double average;
dataFile.open("lab3ScoreData.txt");
outFile.open("lab3AvgOutput.txt");
outFile << fixed << showpoint;
outFile << setprecision(1);
dataFile >> score1 >> score2 >> score3 >> score4 >> score5;
average = (score1 + score2 + score3 + score4 + score5) / 5.0;
outFile << "The average score of the 5 tests taken is " << average << endl;
dataFile.close();
outFile.close();
return 0;
}


Last edited on
@asbsean

I copied your code, created a "lab3ScoreData.txt" file and put it in the same directory as the source file, compiled the source and ran the program. It came out correctly, so, the only thing I figure was wrong on your end, was you did not put the file in the same directory as the source. You could also try putting the text file into your programs compiled directory, and running it there.
Ok sweet, I thought my code was right and thankfully I only need to turn in the code. I thought it might have something to do with that. Thanks for your input
Topic archived. No new replies allowed.