I'd like this code to be minimized, while displaying the exact same stuff.
Specifically, on how to remove some of the repetitions made within the code (such as "if, else if") etc. using other statements or making the compiler go through it faster, as I feel like I lack the experience and the knowledge to do this without messing up everything (such as using switch & case).
For example, when I test for "tf", I'd like not to be forced to repeat the "average" depending on whether or not we add the "TEZA" grade.
#include <iostream>
using namespace std;
int main()
{
string sub, tf;
int m1, m2, m3, m4, sum, TEZA;
double avg, tzm;
cout << "SIMPLE AVERAGE CALCULATOR";
cout << "\n" << "\n" << "Subject at hand?: ";
cin >> sub;
cout << "\n" << "Input the FOUR marks you'd like verified: " << "\n";
cout << "\n" << "M1: ";
cin >> m1;
cout << "\n" << "M2: ";
cin >> m2;
cout << "\n" << "M3: ";
cin >> m3;
cout << "\n" << "M4: ";
cin >> m4;
cout << "\n" << "Would you like to include the TEZA grade?(Y/N): ";
cin >> tf;
sum = m1 + m2 + m3 + m4;
avg = (double) sum / 4;
if (tf == "Y" | tf == "y")
{
cout << "What is the TEZA grade?: ";
cin >> TEZA;
int tzm = ((double) avg * 3 + TEZA) / 4;
cout << "\n" << "Your average grade at " << sub << " is " << tzm << "\n"
<< "\n";
cout << "You got the following mark: ";
if (tzm >= 9 && tzm <= 10)
cout << "A" << "\n";
else if (tzm >= 8 && tzm <= 9)
cout << "B" << "\n";
else if (tzm >= 7 && tzm <= 8)
cout << "C" << "\n";
else if (tzm >= 6 && tzm <= 7)
cout << "D" << "\n";
else if (tzm >= 5 && tzm <= 6)
cout << "E" << "\n";
else if (tzm < 5)
cout << "F" << "\n";
if (tzm >= 5)
{
cout << "DO YOU PASS: " << "\n";
cout << "Yes." << "\n";
}
else
cout << "No." << "\n";
}
else
{
cout << "\n" << "Average at " << sub << " is " << avg << "\n" << "\n";
cout << "You got the following mark: ";
if (avg >= 9 && avg <= 10)
cout << "A" << "\n";
else if (avg >= 8 && avg <= 9)
cout << "B" << "\n";
else if (avg >= 7 && avg <= 8)
cout << "C" << "\n";
else if (avg >= 6 && avg <= 7)
cout << "D" << "\n";
else if (avg >= 5 && avg <= 6)
cout << "E" << "\n";
else if (avg < 5)
cout << "F" << "\n";
cout << "\n" << "DO YOU PASS?: " << "\n";
if (avg >= 5)
cout << "Yes." << "\n";
else
cout << "No." << "\n";
}
}