How to make this if else statement work?

For an assignment in my C++ class, we're to write a code that'll calculate our entire grade. However, the code is supposed to drop the lowest assignment grade, the lowest assignment of 7 (the last assignment, Assignment 8, can not be dropped)

I'm unsure of how to go about this in code--using an if/else statement?
A segment of the code I previously typed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<iomanip>

using namespace std;

int main()
{
	unsigned short int ass1, ass2, ass3, ass4, ass5, ass6, ass7, ass8, lab, mid, fin;
	const float max = 400;
	cout << "Enter assignment 1 points => ";
	cin >> ass1;
	cout << "Enter assignment 2 points => ";
	cin >> ass2;
	cout << "Enter assignment 3 points => ";
	cin >> ass3;
	cout << "Enter assignment 4 points => ";
	cin >> ass4;
	cout << "Enter assignment 5 points => ";
	cin >> ass5;
	cout << "Enter assignment 6 points => ";
	cin >> ass6;
	cout << "Enter assignment 7 points => ";
	cin >> ass7;
	cout << "Enter assignment 8 points => ";
	cin >> ass8;
	
	cout << "Enter lab exercise points => ";
	cin >> lab;
	cout << "Enter midterm points => ";
	cin >> mid;
	cout << "Enter final points => ";
	cin >> fin;
	
	
	cout << "\nAssignment Grades: " << setw(5) << ass1 << setw(5) << ass2 << setw(5) << ass3 << setw(5) << ass4 << setw(5) << ass5 << setw(5) << ass6 << setw(5) << ass7 << setw(5) << ass8 << endl;
	
	if (ass1<=ass2 <=ass3 <=ass4 <=ass5 <=ass6 <=ass7)
	{ 
		ass1=0;
	}
	else if (ass2<=ass1 <=ass3 <=ass4 <=ass5 <=ass6 <=ass7)
	{
		ass2=0;
	}
	else if (ass3<=ass1 <=ass2 <=ass4 <=ass5 <=ass6 <=ass7)
	{
		ass3=0;
	}
	else if (ass4<=ass1 <=ass2 <=ass3 <=ass5 <=ass6 <=ass7)
	{
		ass4=0;
	}
	else if (ass5<=ass1 <=ass2 <=ass3 <=ass4 <=ass6 <=ass7)
	{
		ass5=0;
	}
	else if (ass6<=ass1 <=ass2 <=ass3 <=ass4 <=ass5 <=ass7)
	{
		ass6=0;
	}
	else if (ass7<=ass1 <=ass2 <=ass3 <=ass4 <=ass5 <=ass6)
	{
		ass7=0;
	}
	cout<<"\n"<<ass1<<ass2<<ass3<<ass4<<ass5<<ass6<<ass7<<endl;

I put the last line to see what I was getting.
The input values for assignments 1-8 are 20, 19, 18, 17, 16, 15, 14, 13 respectively. Yet after the if statement, my cout gave me an output of 0 19 18 17 ..etc
This isn't what I want at all because 20 is obviously larger and not equal to the other integers.

Any help would be appreciated; any tips or any critique would be very beneficiary.
It is invalid condition

if (ass1<=ass2 <=ass3 <=ass4 <=ass5 <=ass6 <=ass7)

It is even totally unclear what you are trying to do.
Please open any book on C++ and read how conditions are written.
Consider using for loops instead of repetitive code. It's quicker to write and easier to adapt to changes.
Likewise for variables consider using arrays or vectors instead of sequentially numbered variables.
1
2
3
4
5
6
7
8
9
const int numberOfAssignments = 8;
vector<unsigned short int> ass;
for( int n = 0; n < numberOfAssignments; ++n )
{
  unsigned short int grade;
  cout << "Enter assignment " << (n+1) << " points => ";
  cin >> grade;
  ass.push_back(grade);
}

Using an array/vector will also make it easier to process the data to meet the requirements. So for example to drop the lowest grade you could just sort the array in ascending order and zero the first element.
1
2
sort(ass.begin(), ass.end(), less<int>());
ass[0] = 0;


Last edited on
Thank you Plover! We haven't gotten that far in our class yet, having no idea what a for loop is, but I'll definitely keep your advice on the matter for future ref.

I've discovered a crude solution:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int low = ass1;
	if (ass2 < low)
	{
		low = ass2;
	}
	if (ass3 < low)
	{
		low = ass3;
	}
	if (ass4 < low)
	{
		low = ass4;
	}
	if (ass5 < low)
	{
		low = ass5;
	}
	if (ass6 < low)
	{
		low = ass6;
	}
	if (ass7 < low)
	{
		low = ass7;
	}

Which sort of works when I subtract the assignment grade total by the low.
Topic archived. No new replies allowed.