# Average score

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 04-30-2005
wiz23
Code:

```TotalAverage + AverageDay = TotalAverage; TotalAverage + AverageEvening = TotalAverage;```
• 04-30-2005
7stud
Quote:

Originally Posted by wiz23
Code:

```TotalAverage + AverageDay = TotalAverage; TotalAverage + AverageEvening = TotalAverage;```

1) Those are not legal statements:
Quote:

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.
Quote:

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;
• 04-30-2005
7stud
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.
• 04-30-2005
wiz23
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:

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```
StudentsEvening.txt look like this:

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```
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:
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;

float maxscore;
float minscore;
float allaverage = 0;
char maxTime='D';
char minTime='D';
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)
else if(AverageDay>=75 && AverageDay<=85)
else if(AverageDay>=65 && AverageDay<=75)
else if(AverageDay>=55 && AverageDay<=65)
else

if(maxscore<AverageDay)
{
maxscore=AverageDay;
maxSID=studentdayId;
maxName=givenname+" "+surname;
}
if(minscore>AverageDay)
{
minscore=AverageDay;
minSID=studentdayId;
minName=givenname+" "+surname;
}

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)
else if(AverageEvening>=75 && AverageEvening<=85)
else if(AverageEvening>=65 && AverageEvening<=75)
else if(AverageEvening>=55 && AverageEvening<=65)
else

if(maxscore<AverageEvening)
{
maxscore=AverageEvening;
maxSID=studentdayId;
maxName=givenname+" "+surname;
maxTime='E';
}
if(minscore>AverageEvening)
{
minscore=AverageEvening;
minSID=studentdayId;
minName=givenname+" "+surname;
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 "
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?
• 04-30-2005
Salem
Not only are you posting code without code tags, it also seems to be code containing old mistakes.
• 05-01-2005
7stud
Quote:

I want to calculate the actual average score from these two input test files
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.
• 05-05-2005
henz321
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```
• 05-05-2005
hk_mp5kpdw
Quote:

Originally Posted by henz321
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