Code:TotalAverage + AverageDay = TotalAverage; TotalAverage + AverageEvening = TotalAverage;
Code:TotalAverage + AverageDay = TotalAverage; TotalAverage + AverageEvening = TotalAverage;
1) Those are not legal statements:Originally Posted by wiz23
2) I asked you this:To assign a variable a value, you do this:
var1 = 20;
var2 = 30 + 20 - 10;
var3 = var1 + var2;
Notice how the variable is always on the left of the equals sign when you assign it a value, AND it is the only thing on the left.
where are TotalAverage1 and TotalAverage2 in your reply:What values are stored in TotalAverage1 and TotalAverage2? Post the lines of code where they are assigned values. Remember for a variable to be assigned a value it has to be on the left side of the equals sign
TotalAverage + AverageDay = TotalAverage;
TotalAverage + AverageEvening = TotalAverage;
Last edited by 7stud; 04-30-2005 at 08:55 AM.
You need to set aside your program for awhile and try to write much shorter programs--no more than 5 - 10 lines. Before you can continue, you have to be able to write a program that does this:
1) Declare a variable and initialize it to any value, say 100.
2) Declare another variable and initialize it to, say 50.
3) Add 5 to the first variable.
4) Add 15 to the second variable.
5) Display both variables to a console window.
6) Add 20 and the second variable to the first variable.
7) Display the first variable to the console window.
Last edited by 7stud; 04-30-2005 at 08:54 AM.
I want to calculate the actual average score from these two input test files, one is called StudentsDay.txt and the other one is called StudentsEvening.txt
StudentsDay.txt look like this:
StudentsEvening.txt look like this:Code:Code: s1012 Anne Bennet 45 77 62 18 79 s1236 Tony Bridges 81 83 89 95 63 s2341 Michael Butcher 72 83 48 26 75
I have already got their individual average score from each of the student and now I only want to get the actual average from the 6 students average score. So this is what I meant:Code:Code: s5454 Joe Sunshine 66 89 78 74 85 s5466 Vanessa White 62 77 44 88 79 s5553 Jim Sunder 66 74 48 53 95
Code:
Anne Bennet average is 56.20
Tony Bridges average is 82.20
Michael Butcher average is 60.80
Joe Sunshine average is 78.40
Vanessa While average is 70.00
Jim Sunder average is 67.20
The average of 6 students is 69.13
Here's the code:
Code:
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
ifstream inFileDay;
ifstream inFileEvening;
ofstream outFile;
string studentdayId;
string studenteveningId;
string givenname, surname;
int score1, score2, score3, score4, score5;
int studentcounter;
double AverageDay, AverageEvening;
string grade;
float maxscore;
float minscore;
float allaverage = 0;
char maxTime='D';
char minTime='D';
string maxGrade;
string minGrade;
string maxSID;
string minSID;
string maxName;
string minName;
maxscore=-1;
minscore=101;
inFileDay.open("studentsDay.txt");
inFileEvening.open("studentsEvening.txt");
outFile.open("report_regular.txt",std::ios::trunc) ;
outFile.setf(ios::fixed, ios::floatfield);
outFile.setf(ios::showpoint);
outFile<<setprecision(2);
outFile<<endl<<"+++++Section 1 Student List+++++"<<endl<<endl;
while (!inFileDay.eof() )
{
inFileDay>>studentdayId;
outFile<<studentdayId<<" ";
inFileDay>>givenname>>surname;
outFile<<surname<<", ";
outFile<<givenname<<" ";
outFile<<"D ";
inFileDay>>score1>>score2>>score3>>score4>>score5;
AverageDay=static_cast<double>(score1+score2+score 3+score4+score5)/5.0;
outFile<<AverageDay<<" ";
outFile.setf(ios::right);
if(AverageDay>=85 && AverageDay<=100)
grade="HD";
else if(AverageDay>=75 && AverageDay<=85)
grade="D ";
else if(AverageDay>=65 && AverageDay<=75)
grade="Cr";
else if(AverageDay>=55 && AverageDay<=65)
grade="P ";
else
grade="F ";
outFile<<grade<<endl;
if(maxscore<AverageDay)
{
maxscore=AverageDay;
maxSID=studentdayId;
maxName=givenname+" "+surname;
maxGrade=grade;
}
if(minscore>AverageDay)
{
minscore=AverageDay;
minSID=studentdayId;
minName=givenname+" "+surname;
minGrade=grade;
}
studentcounter++;
}
while (!inFileEvening.eof() )
{
inFileEvening>>studenteveningId;
outFile<<studenteveningId<<" ";
inFileEvening>>givenname>>surname;
outFile<<surname<<", ";
outFile<<givenname<<" ";
outFile<<"E ";
inFileEvening>>score1>>score2>>score3>>score4>>sco re5;
AverageEvening=static_cast<double>(score1+score2+s core3+score4+score5)/5.0;
outFile<<setw(2)<<AverageEvening<<" ";
outFile.setf(ios::right);
if(AverageEvening>=85 && AverageEvening<=100)
grade="HD";
else if(AverageEvening>=75 && AverageEvening<=85)
grade="D ";
else if(AverageEvening>=65 && AverageEvening<=75)
grade="Cr";
else if(AverageEvening>=55 && AverageEvening<=65)
grade="P ";
else
grade="F ";
outFile<<grade<<endl;
if(maxscore<AverageEvening)
{
maxscore=AverageEvening;
maxSID=studentdayId;
maxName=givenname+" "+surname;
maxGrade=grade;
maxTime='E';
}
if(minscore>AverageEvening)
{
minscore=AverageEvening;
minSID=studentdayId;
minName=givenname+" "+surname;
minGrade=grade;
minTime='E';
}
studentcounter++;
allaverage = (AverageDay++ + AverageEvening++)/6;
}
outFile<<"\n+++++Section 2 The Maximum+++++\n\n"
<<maxName<<" ("<<maxSID<<", "<<maxTime<<") is my best student, with "
<<"a score of "<<maxscore<<" ("<<maxGrade<<")\n"<<minName<<" ("<<minSID
<<", "<<minTime<<"), you need to drop this class... you only got a "
<<minscore<<" ("<<minGrade<<')'<<std::flush;
outFile<<"The average of 6 students is" << allaverage << endl;
return 0;
}
The purple text is the part I try to get the actual results from the 6 students average but I still could not get it. I have tried many times. Can somebody help me please?
Not only are you posting code without code tags, it also seems to be code containing old mistakes.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Unfortunately, you can't write programs unless you first learn how to assign a value to a variable. The short program I asked you to complete was meant to teach you how to do that.I want to calculate the actual average score from these two input test files
why is it when i run it, it outputs sumthing like this?
as you can see, it outputs the last student of each txt twice
Code:+++++Section 1 Student List+++++ s1012 Bennet, Anne D 56.20 P s1236 Bridges, Tony D 82.20 D s2341 Butcher, Michael D 60.80 P s3232 Smith, Ellisa D 83.40 D s3232 Smith, Ellisa D 83.40 D s5454 Sunshine, Joe E 78.40 D s5466 White, Vanessa E 70.00 Cr s5553 Sunder, Jim E 67.20 Cr s6532 Kane, Robert E 64.00 P s6533 Stanger, James E 82.00 D s6533 Stanger, James E 82.00 D
Probably because you are testing eof to control your loop. This is bad... as already mentioned earlier in this thread.Originally Posted by henz321
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens