0

I am lost again, I know that there is a way to use push_back to add to the vector, but I am at a loss for how I can actually get it to work. What I am trying to do is add 5 students to a vector (Egrades), and with each student gather 3 separate exam scores and attach them to that students name so that I can compute the averages later.

In my code below, I took out the lines in the cases, and only put student 1 to cut down length.

Where am I going wrong? Did I forget to put something in?

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

using namespace std;


int main(void)

{

    // Delcarations

    int score1;
    int score2;
    int score3;

    int scores[5];

    vector <int> Egrades;

    string student1;
    string student2;
    string student3;
    string student4;
    string student5;

    // array with menu options
    string menu[15];
    menu[0] = "                                 **************";
    menu[1] = "                              ***  MAIN  MENU  ***";
    menu[2] = "                                 **************";
    menu[3] = "                    Please Choose From The Following Options:";
    menu[6] = "  1. Add Student:";
    menu[8] = "  2. Compute Student Test Score Average:";
    menu[10] = "  3. Search A Student Average Test Score:";
    menu[12] = "  4. Compute The Average Of The Average Exams:";
    menu[14] = "  5. Exit";

 char selection;

    cout << "\t\t\t     Enter Your Selection: ", cin >> selection, cout << endl;

        switch (selection)

        {


        case '1':

            system("CLS");

            do
            {

                {
                    cout << "Student Information Section:\n\n";

                    // Student 1 Info
                    cout << "Enter Student 1 Name:\n";
                    cin >> student1; cout << endl;

                    cout << "Enter Exam 1 Score: ";
                    cin >> score1; cout << endl;

                    cout << "Enter Exam 2 Score: ";
                    cin >> score2; cout << endl;

                    cout << "Enter Exam 3 Score: ";
                    cin >> score3; cout << "\n" << endl;
                }

                    system("pause");

                    return main();

            } 
            
            while (cin >> score1, score2, score3);

            break;
                
        case '2':

            break;
            
        case '3':

            break;

        case '4':    

            break;

        case '5':

            exit(-1);

            break;

        default: cout << "\n Invalid selection\n\n";

        }


    return 0;

}
Pierce2307
  • 41
  • 2
  • 3
    Before going into any kind of C++ language details, I would recommend finding any kind of introductory reference to _object oriented programming_, and then returning to this particular task. – dfrib Jul 09 '20 at 10:25
  • 3
    What does `while (cin >> score1, score2, score3);` do? While does not take `;` at the end – kesarling He-Him Jul 09 '20 at 10:25
  • 2
    @d4rk4ng31 It's a `do while` loop. It's a syntax error without `;`. – Thomas Sablik Jul 09 '20 at 10:30
  • 2
    @d4rk4ng31 It reads a value from standard input into `score1`, `score2` part is ignored and lastly `score3` is used as a condition for `while` statement. [Comma operator](https://stackoverflow.com/questions/54142/how-does-the-comma-operator-work) in C++ is a nasty trap for beginners. – Yksisarvinen Jul 09 '20 at 10:31
  • @ThomasSablik, sorry, missed that do :( – kesarling He-Him Jul 09 '20 at 10:33
  • _"... and with each student gather 3 separate exam scores and attach them to that students name ... "_ - this is commonly known as `class` or `struct`. Write a `Student`-class first, because you can't push different datatypes into a vector. – Lukas-T Jul 09 '20 at 10:34
  • You want to add 5 student in a vector in where each will posses 3 different subject marks? – Rohan Bari Jul 09 '20 at 11:18
  • Why would you read the 3 marks individually inside the loop body], and then (try but fail to) read all 3 at once again as the loop condition? – underscore_d Jul 09 '20 at 14:37

0 Answers0