Hey everyone I have been working on this problem for awhile now and I am pretty stuck in my code...I don't think I approached it the right way. It isn't complete, but I have been staring at it for about an hour now and also looking through the web to help me out but its not working out. Can anyone help me out with this code?

This is the problem and what they want:

Write a program that reads a student's name together with hisor her test scores. The program should compute the averagetest score for each student and ssign the appropriate grade. The grade scale is as follows: 90-100, A; 80-89, B; 70-79, C;60-69, D; 0-59, F. Your program must use the followingfunctions:
a. A void function, calculateAverage,to determine the average of the five test scores for eachstudent. Use a loop to read and sum the five testscores. (This function does not output the average testscore. That task must be done in the function main.)
b. A value-returning function,calculateGrade, to determine and return each student's grade. (Thisfunction does not output the grade. That task must be done inthe function main.)
Test your program on the following data. Read the datafrom a file (use an inData.txt) and send the output to afile. Do not use any global variables. Use theappropriate parameters to pass values in and out offunctions.
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63
Sample output:
The output should be of the following form: (fill the last 2columns and the last line showing the class average.)
Student Test1 Test2 Test3 Test4 Test5 Average Grade
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63
Class Average =

``````#include <iostream>
#include <fstream>
#include <string>

using namespace std;

//Declare function Prototype
void calculateAverage(double& avg1, double& avg2, double& avg3, double& avg4, double& avg5 , double& avg6, double& avg7, double& avg8, double& avg9, double& avg10);

int main()
{
//Declare fstream files
ifstream inFile;
ofstream outFile;

//Open file
infile.open("C:\Users\Emcy\Desktop\ch7.txt");
outfile.open("C:\Users\Emcy\Desktop\output.txt");

//Variable declaration
double name;
double test1, test2, test3, tes4, test5;
double& mean1, mean2, mean3, mean4, mean5 , mean6, mean7, mean8, mean9, mean10;
string line1, line2, line3, line4, line5, line6, line7, line8, line9, line10;

//Program purpose
cout << "This program will take 5 test scores from users and calculate \nthe average, then display it in a chart format"<< endl;
system("pause");
system("cls");

//Decimal point: 2
outFile << fixed << showpoint <<setprecision(2);

//Give something for the user to look at
cout << "Gathering Information..." << endl;

//Information Processing
calculateAverage(mean1, mean2, mean3, mean4, mean5 , mean6, mean7, mean8, mean9, mean10);

return 0;
}

void calculateAverage(double& avg1, double& avg2, double& avg3, double& avg4, double& avg5 , double& avg6, double& avg7, double& avg8, double& avg9, double& avg10)
{
double x = 0

while(x <= 10)
{
//1st
if (x = 0)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum1 = sum + num
}
avg1 = sum1 / 5
}
//2nd
else if (x = 1)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum2 = sum + num
}
avg2 = sum2 / 5
}
//3rd
else if (x = 2)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum3 = sum + num
}
avg3 = sum3 / 5
}
//4th
else if (x = 3)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum4 = sum + num
}
avg4 = sum4 / 5
}
//5th
else if (x = 4)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum5 = sum + num
}
avg5 = sum5 / 5
}
//6th
else if (x = 5)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum6 = sum + num
}
avg6 = sum6 / 5
}
//7th
else if (x = 6)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum7 = sum + num
}
avg7 = sum7 / 5
}
//8th
else if (x = 7)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum8 = sum + num
}
avg8 = sum8 / 5
}
//9th
else if (x = 8)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum9 = sum + num
}
avg9 = sum9 / 5
}
//10th
else if (x = 9)
{
double num
double y = 0
while(y <=5)
{
inFile >> num
sum10 = sum + num
}
avg10 = sum10 / 5
}
x++
}
}
{

if (average <= 100 && average >= 90)

else if (average <= 89 && average >=80 )

else if (average <= 79 && average >= 70)

else if (average <= 69 && average >= 60)

else if (average <= 59)

}``````
2
Contributors
1
2
Views
7 Years
Discussion Span
Last Post by jonsca
``````double test1, test2, test3, tes4, test5;

string line1, line2, line3, line4, line5, line6, line7, line8, line9, line10;``````

Look into arrays for these quantities.

Also, when you have:

``````double& mean1, mean2, mean3, mean4, mean5 , mean6, mean7, mean8, mean9, mean10;

see the following example:

``````double * a,b;  //I made this a  pointer instead of a reference but you get the idea
it's equivalent to:
double * a;
double b;``````

I do not believe you are correct in declaring lines 24 and 25 as references. Simply declare the "char &"s as chars as that is what your function is returning. Use arrays for these as well.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.