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.