Hello all.
I am working on a little program here and need some help. The input is 3 test grades that are out of 50 points total, the program takes the higher of the first 2 test grades and adds that to the last test grade to determine a final score.
This is where I need my first bit of help, as you can see the code below isn't quite up to par. It will correctly give you a final grade, but it also gives 2 other grades in addition because of how I set up the if statements. I'm not sure where to add an else because I don't want it to say if you dont get an A then else you get BCDF or something. I was trying to use the && or || possibly but can't figure out how to get what I want.
Also I need help verifying the input the user enters, if they enter negative numbers or letters it crashes the program. Like something that prompts the user "no negative numbers, try again".
# include <string>
# include <iostream>
using namespace std;
int main()
{
string name;
float test1;
float test2;
float test3;
cout << "Welcome to the Grade Calculator Machine. You will enter three test scores." <<endl;
cout << "The higher of the first two test grades will be added with the third test grade" <<endl;
cout << "to determine the final grade average for the course." <<endl<<endl;
cout <<"Enter the student's name:";
getline(cin, name);
cout <<"Please enter test score 1:";
cin >> test1;
cout <<"Please enter test score 2:";
cin >> test2;
cout <<"Please enter test score 3:";
cin >> test3;
if
(test1 > test2)
cout <<"The average for the course = " <<((test1 + test3)/2)*2<<endl;
else
cout <<"The average for the course = " <<((test2 + test3)/2)*2<<endl;
if
((((test1 + test3)/2)*2) >= 90)
cout<<name<<" has earned an A for the course."<<endl;
if
((((test2 + test3)/2)*2) >= 90)
cout<<name<<" has earned an A for the course."<<endl;
if
((((test1 + test3)/2)*2) >= 80 && (((test1 + test3)/2)*2) <=89)
cout<<name<<" has earned a B for the course."<<endl;
if
((((test2 + test3)/2)*2) >= 80 && (((test2 + test3)/2)*2) <=89)
cout<<name<<" has earned a B for the course."<<endl;
if
((((test1 + test3)/2)*2) >= 70 && (((test1 + test3)/2)*2) <=79)
cout<<name<<" has earned a C for the course."<<endl;
if
((((test2 + test3)/2)*2) >= 70 && (((test2 + test3)/2)*2) <=79)
cout<<name<<" has earned a C for the course."<<endl;
if
((((test1 + test3)/2)*2) >= 60 && (((test1 + test3)/2)*2) <=69)
cout<<name<<" has earned a D for the course."<<endl;
if
((((test2 + test3)/2)*2) >= 60 && (((test2 + test3)/2)*2) <=69)
cout<<name<<" has earned a D for the course."<<endl;
if
((((test1 + test3)/2)*2) < 60)
cout<<name<<" has earned an F for the course."<<endl;
if
((((test1 + test3)/2)*2) <60)
cout<<name<<" has earned an F for the course."<<endl;
cout<< "\n \n \nThank you for using the Grade Calulator Machine"<<endl;
return 0;
}