For my class we have to create a program that computes numeric grades for a course. The grades are in a file that will be the input file. Input file follows the following format: Each line contains a students last name, one space, followed by the students last name, then one space, then 10 quiz scores all on one line, each are whole numbers separated by one space. The program should read data from the inputfile and put it in the output file with the same format except there will be an additional number (of type double) at the end of each line. The number will be the average of the ten quizes.
At this point, I am able to get my program to write in the output file the data from the input, however its getting stuck in an infinite loop because my computer slows down and the file sizes are huge. Its also not placing the average on the last line either. Anyone have any advice? This chapter with I/O streams has been pretty confusing to me.
I have two sets of the score, the first one only creates one line and the rest is just random letters for infinity, however its not in a loop.
The second one goes into an infinite loop, but if you close it the original data is stored in the output file, but no average and the file size is huge. The formatting is also off for some reason. http://prntscr.com/8yl0u6
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <fstream>
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
char Name;
int Num_Space, scores;
double total_scores;
outfile.open("Output.dat");
if (outfile.fail())
exit(1);
infile.open("scores.txt");
if (infile.fail())
exit(2);
while (!infile.eof())
{
cout << "in first while loop";
infile.get(Name);
outfile.put(Name);
Num_Space = 0;
while (Num_Space < 2)
{
if (Name == ' ')
{
Num_Space++;
outfile << Name;
}
infile.get(Name);
outfile.put(Name);
}
}
while (infile.eof())
{
total_scores = 0;
infile >> scores;
total_scores += scores;
outfile << scores;
infile >> scores;
total_scores += scores;
outfile << scores;
infile >> scores;
total_scores += scores;
outfile << scores;
infile >> scores;
total_scores += scores;
outfile << scores;
infile >> scores;
total_scores += scores;
outfile << scores;
infile >> scores;
total_scores += scores;
outfile << scores;
infile >> scores;
total_scores += scores;
outfile << scores;
infile >> scores;
total_scores += scores;
outfile << scores;
infile >> scores;
total_scores += scores;
outfile << scores;
outfile << total_scores / 10;
}
outfile.close();
infile.close();
return 0;
}