Having problem set code up for five rows and 4 column. Any ideas have
too do it the code, i am currently using:

cout << setfill(' ') <<setiosflags(ios::left) << setw(11) <<
"Student" << setw(10) << "Quiz1"
<< setw(8) << "Quiz2" << setw(8) << "Quiz3" << setw(8) << "Quiz4"
<< setw(8) << "Average" << setw(8) << "Grade" <<endl;
 
 
if (!inFile)
{
cout << "Unable to open this file." <<endl;
system("PAUSE");
return 1;
}
 
while (inFile >> studentName >> quiz1 >> quiz2 >> quiz3 >> quiz4)
{
 
calculateAverage(quiz1, quiz2, quiz3, quiz4,SAverage);
 
grade = calculateGrade(SAverage);
 
cout << setfill(' ') << setiosflags(ios::left) << setw(11) <<
studentName << setw (10) << quiz1 << setw(8) << quiz2 << setw(8) << quiz3 << setw(8) << quiz4
<< setw(8) << SAverage << setw(8) <<grade<<endl;

I can't understand your question clearly. but if you want to have five columns in output use a gotoxy function! (in VC you have to write gotoxy yourself)

Can you gives us a picture or something that shows how the output
should be?

Student Quiz1 Quiz2 Quiz3 Quiz4 Average Grade
70 80 90 95 72 C
95 85 90 80 66 D
70 80 55 85 54 F
70 45 50 40 34 F
70 85 75 35 60 D
Press any key to continue . . .

Every time i compile it look like this:

Student Quiz1 Quiz2 Quiz3 Quiz4 Average Grade
70 80 90 95 95 72 C
85 90 80 75 85 66 D
70 80 55 85 50 54 F
70 45 50 40 35 34 F
Press any key to continue . . .

cant see what is going wrong any help will greatly be appreciated.
The program is the i'm missing a row and i don't understand why or how to correct it.
so, that i have 5 row and 4 columns.

well if you put your code completely, I will be able to test your program.

Ok, here the complete code.

#include <iostream>
 #include <iomanip>
 #include <fstream>
 
using namespace std;
 
 
 
void calculateAverage(double quiz1, double quiz2, double quiz3, double
quiz4, double& SAverage);
int calculateGrade(double grade);
 
int main()
{
 
double studentName= 0;
int numberOfStudents = 0;
double classAverage = 0;
double SAverage = 0;
double totalAverage = 0; //To add the average of all student averages
char grade;
double quiz1, quiz2, quiz3, quiz4;
 
ifstream inFile; // input stream variable for the student file

inFile.open("open.txt");
 
cout << setfill(' ') <<setiosflags(ios::left) 
<< setw(10) <<"Student" 
<< setw(10) << "Quiz1"
<< setw(10) << "Quiz2" 
<< setw(10) << "Quiz3" 
<< setw(10) << "Quiz4"
<< setw(10) << "Average" 
<< setw(10) << "Grade" <<endl;
 
 
if (!inFile)
{
cout << "Unable to open this file." <<endl;
system("PAUSE");
return 1;
}
 
while (inFile >> studentName >> quiz1 >> quiz2 >> quiz3 >> quiz4)
{
 
calculateAverage(quiz1, quiz2, quiz3, quiz4,SAverage);
grade = calculateGrade(SAverage);
 
cout << setfill(' ') << setiosflags(ios::left) << setw(11) <<
studentName << setw (10) << quiz1 << setw(10) << quiz2 << setw(10) << quiz3 << setw(10) << quiz4
<< setw(10) << SAverage << setw(10) <<grade<<endl;
 
totalAverage = totalAverage + SAverage;
 
numberOfStudents++;
classAverage = totalAverage / numberOfStudents;
}
 
inFile.close();
 
system("PAUSE");
return 0;
}
 
 
 
//function to calculate the average
void calculateAverage(double quiz1, double quiz2, double quiz3, double
quiz4, double& SAverage)
{
 
SAverage = static_cast<double> (quiz1 + quiz2 + quiz3 + quiz4) / 5.0;
 
}
  
int calculateGrade(double SAverage)
{
char grade;
 
if (SAverage <= 100 && SAverage >= 90)
grade = 'A';
else if (SAverage < 90 && SAverage >= 80)
grade = 'B';
else if (SAverage < 80 && SAverage >= 70)
grade = 'C';
else if (SAverage < 70 && SAverage >= 60)
grade = 'D';
else if (SAverage < 60 && SAverage >= 0)
grade = 'F';
else
cout << "Invalid grade " << endl;
 
return grade;
 
}

I also need open.txt file & probably the program that created it.

ok the number in open.txt are:
70 80 90 95 95 85 90 80 75 85 70 80 55 85 50 70 45 50 40 35


The program i'm using is Microsoft visual studio

I think the problem is with the open.txt.
in open.txt file you have 20 items. but you need 25 items! add the items you need!
and a more standard version of your code:

#include <iostream>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
 
//function to calculate the average
void calculateAverage(double quiz1, double quiz2, double quiz3, double quiz4, double& SAverage)
{ 
	SAverage = static_cast<double> (quiz1 + quiz2 + quiz3 + quiz4) / 5.0; 
}
  
int calculateGrade(double SAverage)
{
	char grade;
	 
	if (SAverage <= 100 && SAverage >= 90)
	grade = 'A';
	else if (SAverage < 90 && SAverage >= 80)
	grade = 'B';
	else if (SAverage < 80 && SAverage >= 70)
	grade = 'C';
	else if (SAverage < 70 && SAverage >= 60)
	grade = 'D';
	else if (SAverage < 60 && SAverage >= 0)
	grade = 'F';
	else
	cout << "Invalid grade " << endl;
	 
	return grade; 
}
 
int main()
{	 
	double studentName = 0;
	int numberOfStudents = 0;
	double classAverage = 0;
	double SAverage = 0;
	double totalAverage = 0; //To add the average of all student averages
	char grade;
	double quiz1, quiz2, quiz3, quiz4;
	 
	ifstream inFile; // input stream variable for the student file

	inFile.open("open.txt");
	if (!inFile)
	{
		cout << "Unable to open this file." << endl;
		system("PAUSE");
		return 1;
	} 
	 
	cout << setfill(' ') << setiosflags(ios::left) 
		<< setw(10) << "Student" 
		<< setw(10) << "Quiz1"
		<< setw(10) << "Quiz2" 
		<< setw(10) << "Quiz3" 
		<< setw(10) << "Quiz4"
		<< setw(10) << "Average" 
		<< setw(10) << "Grade" << endl;	 
	 
	
	while (inFile >> studentName >> quiz1 >> quiz2 >> quiz3 >> quiz4)
	{ 
		calculateAverage(quiz1, quiz2, quiz3, quiz4,SAverage);
		grade = calculateGrade(SAverage);		 
		cout << setfill(' ') << setiosflags(ios::left) << setw(11) 
			<< studentName << setw (10) << quiz1 << setw(10) << quiz2 
			<< setw(10) << quiz3 << setw(10) << quiz4
			<< setw(10) << SAverage << setw(10) << grade << endl;
		 
		totalAverage = totalAverage + SAverage;
		 
		numberOfStudents++;
		classAverage = totalAverage / numberOfStudents;
	}
	 
	inFile.close();
	 
	system("PAUSE");
}

And there's some problem with calculateAverage. use this:

void calculateAverage(double quiz1, double quiz2, double quiz3, double quiz4, double& SAverage)
{ 
	SAverage = (double) (quiz1 + quiz2 + quiz3 + quiz4) / 4; 
}

i got it the only problem i'm having now is labeling each row. Thank so much for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.