How can i change this code to get a output like this:

This Program Average grades and output the average and letter grade

Quiz1 Quiz2 Quiz3 Quiz4 Average Grade
s1 70 80 90 95 83.75 B
s2 95 85 90 80 87.5 B
s3 75 85 70 80 77.5 C
s4 55 85 50 70 65 D
s5 45 50 40 35 42.5 F
Press any key to continue . . .

Any help will be great like appreciated.


my current code is:

#include <iostream>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
void calculateAverage(double quiz1, double quiz2, double quiz3, double quiz4, double& SAverage)
{ 
	SAverage = (double) (quiz1 + quiz2 + quiz3 + quiz4) / 4; 
}
  
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()
{	 

	int numberOfStudents = 0;
	double classAverage = 0;
	double SAverage = 0;
	double totalAverage = 0; 
	char grade;
	double quiz1, quiz2, quiz3, quiz4; 
	cout<<"This Program Average grades and output the average and letter grade\n"<<endl;
	ifstream inFile; 

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

current output i'm getting is:
This Program Average grades and output the average and letter grade

Quiz1 Quiz2 Quiz3 Quiz4 Average Grade
70 80 90 95 83.75 B
95 85 90 80 87.5 B
75 85 70 80 77.5 C
55 85 50 70 65 D
45 50 40 35 42.5 F
Press any key to continue . . .

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

How can SAverage be greater than 100 AND less than 90 at the same time?

what questions do you ask???

I read the code and output result from begin to end , can't acquire any function you want to achieve

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

this sentence is right ,syntax and logic

This article has been dead for over six months. Start a new discussion instead.