Skip to content

Instantly share code, notes, and snippets.

@mxdi9i7
Created October 20, 2017 21:36
Show Gist options
  • Save mxdi9i7/7b9ea161b4e15e3833434247a79afe28 to your computer and use it in GitHub Desktop.
Save mxdi9i7/7b9ea161b4e15e3833434247a79afe28 to your computer and use it in GitHub Desktop.
idk
#include <iostream>
#include <string>
using namespace std;
// Write definition for getAverage Function
double getAverage(string className) {
double classAvg;
cout << "Please enter your average for subject " << className << "." << endl;
cin >> classAvg;
if (classAvg < 0 || classAvg > 100) {
cout << "Please enter a number between 0 and 100 !" << endl;
cin >> classAvg;
}
return classAvg;
}
// Write definition for findHighestAverage Function
void getHighestAverage(double englishAvg,double mathAvg,double spanishAvg, double scienceAvg) {
double allAvg[4] = {englishAvg, mathAvg, spanishAvg, scienceAvg};
string allSubjectNames[4] = {"english",
double x = 0.00;
string subjectName;
for (int i = 0; i < 4; i ++) {
if (allAvg[i] > x) {
x = allAvg[i];
}
}
for (int i = 0; i < 4; i ++) {
if (
}
cout << "Your highest class average is " << x << endl;
}
int main() {
// Declare necessary variables
// Call getAverage function for each of the four subjects - English, Math, Spanish, Science
double englishAvg = getAverage("english");
double mathAvg = getAverage("math");
double spanishAvg = getAverage("spanish");
double scienceAvg = getAverage("science");
// Call findHighestAverage function
getHighestAverage(englishAvg, mathAvg, spanishAvg, scienceAvg);
return 0;
}
@ssysm
Copy link

ssysm commented Oct 20, 2017

#include
#include
using namespace std;

// Write definition for getAverage Function
double getAverage(string className) {
double classAvg;
cout << "Please enter your average for subject " << className << "." << endl;
cin >> classAvg;
if (classAvg < 0 || classAvg > 100) {
cout << "Please enter a number between 0 and 100 !" << endl;
cin >> classAvg;
}
return classAvg;
}
// Write definition for findHighestAverage Function
void getHighestAverage(double englishAvg,double mathAvg,double spanishAvg, double scienceAvg) {

double allAvg[4] = {englishAvg, mathAvg, spanishAvg, scienceAvg};
string allSubjectNames[4] = {"english","math","spanish","science"};
double x = 0.00;
string subjectName;
for (int i = 0; i < 4; i ++) {
	if (allAvg[i] > x) {
		x = allAvg[i];
		subjectName = allSubjectNames[i];
	}
}
cout << "Your highest class "<< subjectName << " average is " << x << endl;

}

int main() {
// Declare necessary variables

// Call getAverage function for each of the four subjects - English, Math, Spanish, Science
double englishAvg = getAverage("english");
double mathAvg = getAverage("math");
double spanishAvg = getAverage("spanish");
double scienceAvg = getAverage("science");
// Call findHighestAverage function
getHighestAverage(englishAvg, mathAvg, spanishAvg, scienceAvg);

return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment