title: C++ automated scoring system
body: <p>I am having trouble completing an assignment according to specifications.  Here is the assignment scenario:</p>
  <blockquote>
  <p>A college is in desperate need of an automated test scoring system. Using C++, write a scoring system for the college and score the tests of at least five students.</p>
  <p>To create the scoring system, follow the steps below:</p>
  <p>First ask for the number of questions in the test</p>
  <p>Then asks for the correct answers for each question. Note that multiple choice tests and questions will have answers from A to D.</p>
  <p>Ask for the number of students and process each student by asking for their name and then loop through the questions asking for the student's answer.</p>
  <p>Score each question.</p>
  <p>After the last question calculate the students score and display &quot;Student 'insert student name' scored 10 out of 20 or 50%.&quot;</p>
  <p>Repeat until all the students have been scored.</p>
  <p>After all students are scored, insert a print a class list of all the student's results in the same manner as before.</p>
  </blockquote>
  <p>This is what I have so far:</p>
  <pre><code>#include &quot;stdafx.h&quot;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      //declare variables
      char choice;
      string studentName;
      vector&lt;char&gt; answers;
      vector&lt;string&gt; names;
      int getStudents();
      int getQuestions();
      
      //calls function to get number of questions
      float questions = getQuestions();
  
  
      //Get answers
      for (int i = 0; i &lt; questions; ++i) {
          cout &lt;&lt; &quot;What is the answer for question &quot; &lt;&lt; i + 1 &lt;&lt; endl;
          cin &gt;&gt; choice;
          answers.push_back(choice);
      }
  
      //Get number of students
      int students = getStudents();
  
  
      //Get student names
      for (int i = 0; i &lt; students; i++) {
          cout &lt;&lt; &quot;Student &quot; &lt;&lt; i + 1 &lt;&lt; &quot;, what is your name?&quot; &lt;&lt; endl;
          cin &gt;&gt; studentName;
          names.push_back(studentName);
      }
  
      float score = 0;
      char studentAnswer;
      vector&lt;char&gt; userAnswer;
      vector&lt;float&gt; finalScore;
          
      //gets student answers
      for (int i = 0; i &lt; students; i++) {
          for (int j = 0; j &lt; questions; j++) {
              cout &lt;&lt; names[i] &lt;&lt; &quot;, what is your answer for question &quot; &lt;&lt; j + 1 &lt;&lt; &quot;?&quot; &lt;&lt; endl;
              cin &gt;&gt; studentAnswer;
              userAnswer.push_back(studentAnswer);
          }
      }
  
      
  
      //calculates student scores
      for (int i = 0; i &lt; students; i++) {
          for (int j = 0; j &lt; questions; j++) {
              if (userAnswer[j] == answers[j])
                  score = score + 1;
                  }       
          finalScore.push_back(score);
      }
  
      //outputs scores
      for (int i = 0; i &lt; students; i++) {
          cout &lt;&lt; names[i] &lt;&lt; &quot; scored &quot; &lt;&lt; finalScore[i] &lt;&lt; &quot; out of &quot; &lt;&lt; questions &lt;&lt;
              &quot; or &quot; &lt;&lt; (finalScore[i] / questions) * 100 &lt;&lt; &quot;%&quot; &lt;&lt; endl;
      }
  
      
  
      system(&quot;pause&quot;);
      return 0;
  }
  //function to get number of questions
  int getQuestions()
  {
      int questions;
      cout &lt;&lt; &quot;How many questions are there?&quot; &lt;&lt; endl;
      cin &gt;&gt; questions;
      return questions;
  }
  //function to get number of students
  int getStudents()
  {
      int students;
      cout &lt;&lt; &quot;How many students are there?&quot; &lt;&lt; endl;
      cin &gt;&gt; students;
      return students;
  }
  </code></pre>
  <p>The values returned for final score are not accurate and I can not find where the error is occurring.</p>
  <p>Also for the sorting in the last step, I have been asked to sort as a combination of the scores in descending order and names in ascending or alphabetical order.  I am able to sort these independently of each other but not sure how to combine them and sort them that way.</p>