But how can it determine whether the student is day or evening because I am reading from the 2 text files?
Printable View
But how can it determine whether the student is day or evening because I am reading from the 2 text files?
Which lines of code read from the file containing evening students?
This line for day: inFileDay
This line for evening: inFileEvening
That is why I am having trouble for displaying the D or E for students because there are 2 text files as they will be output to report_regular.txtCode:inFileDay.open("studentsDay.txt");
inFileEvening.open("studentsEvening.txt");
outFile.open("report_regular.txt");
No, those lines open the files. Which lines read from the file containing evening students.
ifstream inFileEvening? So how does this line let me put D or E.
whenever you're reading the information from inFileEvening, put an E in the file... I see you're having problems with the logic, so here's how your code should look:...of course that's after you've opened all the files and declared all the variables...Code://loop 1 - read in from inFileEvening
//do the calculations
outFile << surname <<' '<< givenname <<' '<< 'E' <<' '<< average << endl;
//loop 2 - read in from inFileDay
//do the calculations
outFile << surname <<' '<< givenname <<' '<< 'D' <<' '<< average << endl;
//close all the files and you're done
Thankx, so do I declare the D or E as char so it is for example:
Code:char de
...or you could just output them directly as I did...Quote:
Originally Posted by wiz23
I now need to find out the maximum and minimum average score from the student in both day and evening from the text files. I have done these but I think is wrong:
Code:while (max==Average)
{
(count = 1; count <6; count++)
max = larger(max,Average);
}
outFile<<studentdayId<<" ";
outFile<<surname<<", ";
outFile<<givenname<<" ";
outFile << max<<endl;
outFile<<"D ";
outFile<<Average<<" ";
while (min==Average)
{
(count = 1; count <6; count++)
min = smaller(min,Average);
}
outFile<<studentdayId<<" ";
outFile<<surname<<", ";
outFile<<givenname<<" ";
outFile << min<<endl;
outFile<<"D ";
outFile<<Average<<" ";
1) The statements inside the the while loop will only execute if max is equal to Average, so testing which is larger doesn't do anything--they are the same.Code:while (max==Average)
{
(count = 1; count <6; count++)
max = larger(max,Average);
}
2)That's not a legal C++ statment.Code:while (max==Average)
{
(count = 1; count <6; count++)
max = larger(max,Average);
}
3) Did you define a larger() function somewhere?Code:while (max==Average)
{
(count = 1; count <6; count++)
max = larger(max,Average);
}
Do you mean declaring larger(max, Average)? I declare them as double for larger, max, Average.
I am trying to find the maximum and minimum average score from the student in both day and evening from the text files.
Now I want to find the maximum average from day then find the maximum from evening and then compare both to see which is larger. Is this the right approach? I does this code for finding the maximum and minimum from day but once I complie and run it didn't show anything:
Code:while (!inFileDay.eof() )
{
int score1, score2, score3, score4, score5;
int studentcounter;
double AverageDay, AverageEvening, largest = 0;
inFileDay>>score1>>score2>>score3>>score4>>score5;
AverageDay=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
studentcounter++;
{
while (studentcounter<=23)
{
++studentcounter;
if (AverageDay > largest)
AverageDay = largest;
}
outFile<<AverageDay<<endl;
}
}
while (!inFileEvening.eof() )
{
inFileEvening>>score1>>score2>>score3>>score4>>score5;
AverageEvening=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
studentcounter++;
{
while (studentcounter<=23)
{
++studentcounter;
if (AverageEvening > largest)
AverageEvening = largest;
}
outFile<<AverageEvening<<endl;
}
}
if (AverageDay > AverageEvening)
{
outFile << AverageDay <<endl;
else
outFile << AverageEvening <<endl;
}
...do you really even know any C/C++? or any programming language at all?Quote:
Originally Posted by wiz23
you're using larger as a function (or a subroutine in other languages), which has to be defined before you can use it... for example, your code should look something like this:and yes, I did give you the algoritm to get your average... just to show you that you don't need to do that in a function...Code:double larger(double max,double Average);
int main()
{
...
max=larger(max,Average);
...
}
double larger(double max,double Average)
{
return (max>Average?max:Average);
}
Can somebody check this code as I need to output the maximum and minimum average score:
Code:while (!inFileDay.eof() )
{
int score1, score2, score3, score4, score5;
int studentcounter;
double AverageDay, AverageEvening, largest = 0;
inFileDay>>score1>>score2>>score3>>score4>>score5;
AverageDay=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
studentcounter++;
{
while (studentcounter<=23)
{
++studentcounter;
if (AverageDay > largest)
AverageDay = largest;
}
outFile<<AverageDay<<endl;
}
}
while (!inFileEvening.eof() )
{
inFileEvening>>score1>>score2>>score3>>score4>>score5;
AverageEvening=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
studentcounter++;
{
while (studentcounter<=23)
{
++studentcounter;
if (AverageEvening > largest)
AverageEvening = largest;
}
outFile<<AverageEvening<<endl;
}
}
if (AverageDay > AverageEvening)
{
outFile << AverageDay <<endl;
else
outFile << AverageEvening <<endl;
}
if you want us to try something, please include all your code... but from what I saw:try formatting your code a little better, too... the colors are extra, but at least try keeping the spacing up...Code:while (!inFileDay.eof() )
{
int score1, score2, score3, score4, score5;
int studentcounter;
double AverageDay, AverageEvening, largest = 0;
inFileDay>>score1>>score2>>score3>>score4>>score5;
AverageDay=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
studentcounter++; //did you initialize
{
while (studentcounter<=23) //rethink this loop
{
++studentcounter; //did you want to reinitialize this?
if (AverageDay > largest)
AverageDay = largest;
}
outFile<<AverageDay<<endl;
}
}
while (!inFileEvening.eof() )
{
inFileEvening>>score1>>score2>>score3>>score4>>score5;
AverageEvening=static_cast<double>(score1+score2+score3+score4+score5)/5.0;
studentcounter++; //where was studentcounter initialized?
{ //why this bracket?
while (studentcounter<=23) //rethink this loop
{
++studentcounter; //did you want to reinitialize this
if (AverageEvening > largest)
AverageEvening = largest;
}
outFile<<AverageEvening<<endl;
}
}
if (AverageDay > AverageEvening)
{
outFile << AverageDay <<endl;
} //don't forget your brackets
else
{ //again, watch that
outFile << AverageEvening <<endl;
}
also, I can tell it's not going to work, because all you read in are the scores... you're forgetting about the names and student ID.