I am getting a very minor error in my program, hopefully someone will be able to fix this easily (I am definitely a beginner): I need my program to output grades for an average of four program scores, three test scores, a course average, and a letter grade for the course. Here is the grading scale for the letter grade:
>=90 :A
80-89:B (HOWEVER, if any of the test scores is >=95, the letter grade is a A-)
70-79:C (HOWEVER, if any of the test scores is >=95, the letter grade is a B-)
<70:F
My program works fine, all the letter grades output correctly except for ONE: when it is supposed to output a B-, it INSTEAD OUTPUTS AN A-. Here is the code, I assume that is an the issue with the nested if:
#include <iostream>
#include <iomanip>
#include <fstream>
usingnamespace std;
int main (){
system ("color f0");
//Do while loop for another student
char anotherStudent;
do
{
//declarations
string fName,lName,lGrade;
char mInitial;
float FstPscore,SndPscore,TrdPscore,FrthPscore;
float FstTscore,SndTscore,TrdTscore;
float pAverage,tAverage,cAverage;
//Program Input
cout<<"Student Grade Calculator"<<endl;
cout<<endl;
cout<<"Please enter your first name, middle initial, and last name: "<<endl;
cin>>fName>>mInitial>>lName;
cout<<endl;
cout<<"Thank you, your name is "<<fName<<" "<<mInitial<<" "<<lName<<endl;
cout<<endl;
cout<<"Please enter the first program score <0-100>: ";
cin>>FstPscore;
cout<<endl;
cout<<"You entered "<<FstPscore<<endl;
cout<<endl;
cout<<"Please enter the second program score <0-100>: ";
cin>>SndPscore;
cout<<endl;
cout<<"You entered "<<SndPscore<<endl;
cout<<endl;
cout<<"Please enter the third program score <0-100>: ";
cin>>TrdPscore;
cout<<endl;
cout<<"You entered "<<TrdPscore<<endl;
cout<<endl;
cout<<"Please enter the fourth program score <0-100>: ";
cin>>FrthPscore;
cout<<endl;
cout<<"You entered "<<FrthPscore<<endl;
cout<<endl;
cout<<"Please enter the first test score <0-100>: ";
cin>>FstTscore;
cout<<endl;
cout<<"You entered "<<FstTscore<<endl;
cout<<endl;
cout<<"Please enter the second test score <0-100>: ";
cin>>SndTscore;
cout<<endl;
cout<<"You entered "<<SndTscore<<endl;
cout<<endl;
cout<<"Please enter the third test score <0-100>: ";
cin>>TrdTscore;
cout<<endl;
cout<<"You entered "<<TrdTscore<<endl;
cout<<endl;
//Average Calculations
pAverage=(FstPscore+SndPscore+TrdPscore+FrthPscore)/4;
tAverage=(FstTscore+SndTscore+TrdTscore)/3;
cAverage=(pAverage+tAverage)/2;
//Nested If
if (cAverage>=90) {lGrade = "A";}
elseif (cAverage>=80&&FstTscore>=95||SndTscore>=95||TrdTscore>=95) {lGrade = "A-";}
elseif (cAverage>=80) {lGrade = "B";}
elseif (cAverage>=70&&FstTscore>=95||SndTscore>=95||TrdTscore>=95) {lGrade = "B-";}
elseif (cAverage>=70) {lGrade = "C";}
else {lGrade = "F";}
//Program Output
cout<<"123456789012345678901234567890123456789012345"<<endl;//45 spaces
cout<<setfill('*');
cout<<setw(45)<<"*"<<endl;
cout<<"Name: "<<fName<<" "<<mInitial<<" "<<lName<<endl;
cout<<endl;
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Program Average.......... "<<pAverage<<endl;
cout<<endl;
cout<<"Test Average............. "<<tAverage<<endl;
cout<<endl;
cout<<"Course Average........... "<<cAverage<<endl;
cout<<endl;
cout<<"Letter Grade............. "<<lGrade<<endl;
cout<<endl;
cout<<setfill('*');
cout<<setw(45)<<"*"<<endl;
//2nd part of do while loop
cout<<"Please enter Y for another student or N to quit:";
cin>>anotherStudent;
cout<<endl;
}while(anotherStudent=='y');
cout<<endl;
system ("pause");
return 0;
}//end of main