I have been fiddling with these damn loops for hours. I am new to c++ but not too programming. My teacher is absolutely worthless. she refuses to help me and explains things very poorly. I have a 100 % on the assignments in the class and do not wish to drop because of this one. I read the sticky about students and believe me I am not one of them . I have been up for like 12 hours messing with this. Here is the problem: I am supposed to read numbers out of a file piano.data and put the results into report.out. The piano file is structured like this
4 // number of categories
6010 // student number 1 // level of proficiency
7.0 8.5 7.0 8.5 //scores judge 1
7.0 7.5 8.0 7.5 //scores judge 2
7.5 8.0 7.5 8.0 //scores judge 3
-1 //no more judges
6012 1
7.5 7.0 9.5 9.0
7.0 6.0 10.0 10.0
7.5 7.5 10.0 9.5
-1
The problem I have is that I can put the header in, read the student number, display it and use a switch operater to display profieciency. I then have a counter control set up to spit out which judge and then the scores are listed after. Problem being is that it will only display the first list of scores or if i fiddle with it it will just display shit loads of judges with correct scores but eventually the numbers get garbled. It will never
repeat the student part or the profiency. I believe a sentinal controls one of loops and she wants a for controlled counter statement. then the outer loop searches for end of file i think. I dont know it may be four loops. I am submitting the one that works the best because the ones with more loops spit out all kinds of wierd stuff. here is my code:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
void SetFormat (ofstream& fout);
void Header (ofstream& fout);
double Process (ifstream& fin, ofstream& fout);
void PrintHigh (ofstream& fout, double highScore);
int main()
{
ifstream fin;
ofstream fout;
double highScore;
fin.open("Piano.data");
if (fin.fail())
{
cout << "ERROR: Input File\n";
exit(1);
}
fout.open("Report.out");
if (fout.fail())
{
cout << "ERROR: Output File\n";
exit(1);
}
SetFormat(fout);
Header(fout);
highScore = Process(fin, fout);
fin.close();
fout.close();
return 0;
}
void SetFormat(ofstream& fout)
{
fout.setf(ios::fixed);
fout.setf(ios:: showpoint);
fout.precision(1);
return;
} // end SetFormat
void Header(ofstream& fout)
{
fout << " \n\n Federation of Music Teachers\n";
fout << " Mardi Gras Piano Invitational Competition\n";
fout << " Baton Rouge, Louisiana\n";
return;
} // end header
double Process(ifstream& fin, ofstream& fout)
{
int numCategories;
int pianoPlayer;
int level;
int judgeNumber = 0;
double scoreType_1, scoreType_2, scoreType_3, scoreType_4;
double highScore = -999999.99;
double score;
double totalScore;
fin >> numCategories;
while (! fin.eof())
{
fin >> pianoPlayer;
fin >> level;
fout << "Piano Player: ";
fout.width(1);
fout << pianoPlayer << "\n";
fout << "Level: " << level << "\n\n";
switch(level)
{
case 1:
fout << " Primary\n";
break;
case 2:
fout << " Intermediate\n";
break;
case 3:
fout << " Advanced Intermediate\n";
break;
case 4:
fout << " Senior\n";
break;
default:
cout << " Invalid Code\n";
break;
}
while (scoreType_1 != -1)
{
judgeNumber ++;
fin >> scoreType_1 >> scoreType_2 >> scoreType_3 >> scoreType_4;
fout << "Judge ";
fout << judgeNumber << " ";
score = scoreType_1 + scoreType_2 + scoreType_3 + scoreType_4;
fout.width(6);
fout << "Type 1 Type 2 Type 3 Type 4 Score\n";
fout << scoreType_1 << " " << scoreType_2 << " " <<scoreType_3
<< " " << scoreType_4 << score;
totalScore += score;
fout << "\n----------------------------------------\n";
fout << "Total: ";
fout << totalScore;
}
void PrintHigh (ofstream& fout, double highScore);
{
fout << "\n\n\n";
fout << "Highest Score: ";
fout.width(5);
fout << highScore << endl;
return highScore;
} //end printhigh
}
}
If someone could just point me in the right direction with how to go in and out of the loops I could do the rest.