Help with conditional else if statements

Hello, I'm trying to run some code that takes the average test scores of students and determines wether or not they are in good academic standing and can graduate if they are seniors. In the second section of else if statements, I have a line that has 2 conditions in it, and I don't know what's wrong with the syntax of them (starred lines). Any help with this is very appreciated!

If the code is too hard to read here's a jsfiddle link to the code : https://jsfiddle.net/eichtower15/n8ov89jf/

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

string fullName, honorsRank, className;
int year;
int testScore1, testScore2, testScore3, testScore4, testScore5;
int avgScore;

int main()
{
// Retrieve students name
cout << "Please enter your full name: ";
cin >> fullName;

// Retrieve students year of high school
cout << "Please indicate which year of High School you are currently in: ";
cin >> year;

// As for all five test scores
cout << "Please enter your score for the first test: ";
cin >> testScore1;

cout << "Please enter your score for the second test: ";
cin >> testScore2;

cout << "Please enter your score for the third test: ";
cin >> testScore3;

cout << "Please enter your score for the fourth test: ";
cin >> testScore4;

cout << "Please eneter your score for the fifth test: ";
cin >> testScore5;

//Compute the average score of the five tests
avgScore = (testScore1 + testScore2 + testScore3 + testScore4 + testScore5)/5;

// Assign either freshman, sophomore, junior, or senior to the numbered year of high school
if (year == 1)
className = "Freshman";
else if (year == 2)
className = "Sophomore";
else if (year == 3)
className = "Junior";
else if (year == 4)
className = "Senior";

cout << "Name........ " << fullName;
cout << "Year........ " << className;
cout << "Scores...... " << testScore1 << testScore2 << testScore3 << testScore4 << testScore5;
cout << "Average..... " << avgScore;


// Determine students academic standing
if (avgScore >= 97.0)
honorsRank = "**High Honors**", cout << honorsRank << "Note: This student IS ELIGIBLE for graduation";
else if (avgScore >= 95.0)
honorsRank = "**Honors**", cout << honorsRank << "Note: This student IS ELIGIBLE for graduation";
else if (avgScore >= 90.0)
honorsRank = "**Honorable Mention**", cout << honorsRank << "Note: This student IS ELIGIBLE for graduation";
else if (avgScore < 65.0) && (year == 4)*********
cout << "Note: This student is NOT ELIGIBLE for graduation";
else if (avgScore < 65.0) && (year < 4)*********
cout << "Note: This student has been placed on academic probation";
}
return 0;
(avgScore < 65.0) && (year == 4) and (avgScore < 65.0) && (year < 4) are conditions, so you need to place them inside parentheses
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post, highlight your code and click the <> button on the right.

int testScore1, testScore2, testScore3, testScore4, testScore5;
Consider using arrays instead.
1
2
const int NUM_TESTS = 5;
int test_scores[NUM_TESTS] = { 0 };

Then, instead of doing
1
2
cout << "Please enter your score for the first test: ";
cin >> testScore1;

multiple times, you can just do
1
2
3
4
for( int i = 0; i < NUM_TESTS; i++ ) {
    cout << "Please enter score for test #" << i + 1 << ": ";
    cin >> testScores[i];
}

Apply the same logic for calculating the average.

1
2
3
4
5
6
7
8
if (year == 1)
className = "Freshman";
else if (year == 2)
className = "Sophomore";
else if (year == 3)
className = "Junior";
else if (year == 4)
className = "Senior";

A switch statement could be used to improve readability.
1
2
3
4
5
6
7
switch( year )
{
case 1: className = "Freshman"; break;
case 2: className = "Sophomore"; break;
case 3: className = "Junior"; break;
case 4: className = "Senior"; break;
}
Last edited on
Topic archived. No new replies allowed.