
Patrick B. answered 08/14/20
Math and computer tutor/teacher
using namespace std;
#include <iostream>
int input_grade()
{
int iGradeReturn=-1;
while (
(iGradeReturn<0) || (iGradeReturn>100)
)
{
cout << "Please input the grade :>";
cin >> iGradeReturn;
}
return(iGradeReturn);
}
bool Pass( int * grades)
{
bool boolReturn=false; //assumes failure until proven otherwise
int numPassingScores=0;
double gradeSum=0;
for (int iLoop=0; iLoop<3; iLoop++)
{
if (grades[iLoop]>=40)
{
numPassingScores++;
}
gradeSum += grades[iLoop];
}
switch (numPassingScores)
{
case 0:
case 1:
{
break; // FAIL !!!
}
case 2:
{
//1 failing score - the average must be at least 50
double avgGrade = gradeSum/3;
boolReturn = (avgGrade>=50) ? true : false;
cout << "Grade avearage = " << avgGrade << endl;
break;
}
case 3:
{
boolReturn = true;
break;
}
}
return(boolReturn);
}
bool AskAgain()
{
char chResponse='?';
while ((chResponse !='Y') && (chResponse !='N'))
{
cout << "Another ??? Y/N :>";
cin >> chResponse;
//could use toupper() but oh well
if (chResponse=='y') { chResponse='Y'; }
if (chResponse=='n') { chResponse='N'; }
}
bool boolReturn = (chResponse=='Y') ? true : false;
return(boolReturn);
}
int main()
{
bool done_flag = false;
int grades[3];
while (!done_flag)
{
for (int iLoop=0; iLoop<3; iLoop++)
{
grades[iLoop] = input_grade();
}
if (Pass(grades))
{
cout << "PASS" << endl;
}
else
{
cout << "FAIL" << endl;
}
done_flag = !AskAgain();
}
}