#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

struct student {
    string name;
    int grade;
    string letter_grade;

};

int main() {
    // this is incorrect: typedef struct student1;
    struct student student1;
    struct student student2;
    int lab1, lab2, lab3, lab4, lab5, lab6, lab7, lab8, lab9, lab10, lab11;
    int exam1, exam2, final;
    int late_days;
    int late_daytotal = 0;
    int exam_late_days;
    int exam_late_days_total = 0;
    string name;

    for(int i = 1; i<3; i++){
        cout << "Please enter name of student: " << endl;
        cin >> name;
        cout << "Please enter grade for lab 1: " << endl;
        cin >> lab1;
        if(lab1 >20 or lab1 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-2 or late_days > 2){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 2: " << endl;
        cin >> lab2;
        if(lab2 >20 or lab2 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-2 or late_days > 2){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 3: " << endl;
        cin >> lab3;
        if(lab3 >30 or lab3 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-3 or late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 4: " << endl;
        cin >> lab4;
        if(lab4 >30 or lab4 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-3 or late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 5: " << endl;
        cin >> lab5;
        if(lab5 >30 or lab5 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-3 or late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 6: " << endl;
        cin >> lab6;
        if(lab6 >30 or lab6 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-3 or late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 7: " << endl;
        cin >> lab7;
        if(lab7 >30 or lab7 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-3 or late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 8: " << endl;
        cin >> lab8;
        if(lab8 >30 or lab8 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-3 or late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 9: " << endl;
        cin >> lab9;
        if(lab9 >20 or lab9 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-2 or late_days > 2){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 10: " << endl;
        cin >> lab10;
        if(lab10 >20 or lab10 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-2 or late_days > 2){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter grade for lab 11: " << endl;
        cin >> lab11;
        if(lab11 >40 or lab11 < 0){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?: (indicate early days by negative number, late days by positive" << endl;
        cin >> late_days;
        if(late_days <-4 or late_days > 4){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        late_daytotal = late_daytotal + late_days;
        cout << "Please enter exam 1 score: " << endl;
        cin >> exam1;
        if(exam1 < 0 or exam1 > 100){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?"  << endl;
        cin >> exam_late_days;
        if(exam_late_days < 0 or exam_late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        exam_late_days_total = exam_late_days_total + exam_late_days;
        cout << "Please enter exam 2 score: " << endl;
        cin >> exam2;
        if(exam2 < 0 or exam2 > 100){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?"  << endl;
        cin >> exam_late_days;
        if(exam_late_days < 0 or exam_late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        exam_late_days_total = exam_late_days_total + exam_late_days;
        cout << "Please enter final score: " << endl;
        cin >> final;
        if(final < 0 or final > 100){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        cout << "Were there late days/early days?"  << endl;
        cin >> exam_late_days;
        if(exam_late_days < 0 or exam_late_days > 3){
            cout << "This is not in the range!" << endl;
            return 0;
        }
        exam_late_days_total = exam_late_days_total + exam_late_days;

        int total_labs = lab1+lab2+lab3+lab4+lab5+lab6+lab7+lab8+lab9+lab10+lab11;
        int total_exam = exam1 + exam2 + final;
        int final_grade = total_labs + total_exam;
        if(late_daytotal < 0){
            final_grade = final_grade + abs(late_daytotal);
        }
        else{
            final_grade = final_grade - late_daytotal;
        }
        final_grade = final_grade - exam_late_days_total*20;
        string letter_grade;
        if(final_grade >= 570)
            letter_grade = "A";
        if(final_grade <570 && final_grade >=540)
            letter_grade = "A-";
        if(final_grade < 540 && final_grade >= 522)
            letter_grade = "B+";
        if(final_grade < 522 && final_grade >= 498)
            letter_grade = "B";
        if(final_grade < 498 && final_grade >= 480)
            letter_grade = "B-";
        if(final_grade < 480 && final_grade >= 462)
            letter_grade = "C+";
        if(final_grade < 462 && final_grade >= 438)
            letter_grade = "C";
        if(final_grade < 438 && final_grade >= 420)
            letter_grade = "C-";
        if(final_grade < 420 && final_grade >= 402)
            letter_grade = "D+";
        if(final_grade < 402 && final_grade >= 378)
            letter_grade = "D";
        if(final_grade < 378 && final_grade >= 360)
            letter_grade = "D-";
        if(final_grade < 360)
            letter_grade = "E";

        // something looks iffy here: (check your warnings (read all the words (even 'assignment')))
        if (i == 1) {
            student1.name = name;
            student1.grade = final_grade;
            student1.letter_grade = letter_grade;
        }
        else {
            student2.name = name;
            student2.grade = final_grade;
            student2.letter_grade = letter_grade;
        }
    }
    int order = 0;
    cout << "Please enter what order you want to see the students: " << endl;
    cout << "enter 1 for alphabetical or 2 for highest score first: " << endl;
    cin >> order;
    if(order > 2 or order < 1) {
        cout << "out of range" <<endl;
        return 0;
    }
    if(order == 1){
        if(student1.name < student2.name) {
            cout << "name " <<  student1.name << endl;
            cout << "points " <<  student1.grade << endl;
            cout << "letter grade " << student1.letter_grade << endl;
            cout << "name " << student2.name << endl;
            cout << "points " << student2.grade << endl;
            cout << "letter grade " << student2.letter_grade << endl;
        }
        else {
            cout << "name " << student2.name << endl;
            cout << "points " << student2.grade << endl;
            cout << "letter grade " << student2.letter_grade << endl;
            cout << "name " <<  student1.name << endl;
            cout << "points " <<  student1.grade << endl;
            cout << "letter grade " << student1.letter_grade << endl;
        }
    }
    if(order == 2){
        if(student1.grade > student2.grade){
            cout << "name " <<  student1.name << endl;
            cout << "points " <<  student1.grade << endl;
            cout << "letter grade " << student1.letter_grade << endl;
            cout << "name " << student2.name << endl;
            cout << "points " << student2.grade << endl;
            cout << "letter grade " << student2.letter_grade << endl;
        }
        else {
            cout << "name " << student2.name << endl;
            cout << "points " << student2.grade << endl;
            cout << "letter grade " << student2.letter_grade << endl;
            cout << "name " <<  student1.name << endl;
            cout << "points " <<  student1.grade << endl;
            cout << "letter grade " << student1.letter_grade << endl;
        }
    }
}
