Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. //PART 2//
  2. #include "pch.h"
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     char ans;
  10.     do
  11.     {
  12.         int numStudents, score, totalscore = 0, highestScore = 0, average, difference;
  13.         string studentName, highstudent; // string is used to get full name stored
  14.                                          // can not get full name store without use of underscore
  15.         cout << "Enter number of students:" << endl;
  16.         cin >> numStudents;
  17.  
  18.        
  19.         int i = 0;
  20.         while (i < numStudents)
  21.  
  22.             //for (int i = 0; i < numStudents; i++)
  23.         { // begin while loop
  24.             cout << "Enter the students name:" << endl;
  25.             cin >> studentName;
  26.             cout << "Enter score:" << endl;
  27.             cin >> score;
  28.  
  29.             //add score to total score to calculate the average
  30.             totalscore = totalscore + score;
  31.  
  32.             // highest score will be equal to score if score is greater than highest score
  33.             // if if statement is true it must store the studentname of highest score
  34.             if (score > highestScore)
  35.             {
  36.                 highestScore = score;
  37.                 highstudent = studentName;
  38.  
  39.             }
  40.             //else
  41.             cout << "The student with the highest score is " << highstudent << " with a score of " << highestScore << endl;
  42.  
  43.             i++; // this alternates the loop control variable
  44.         }//while loop ends
  45.  
  46.         average = totalscore / numStudents;
  47.         difference = highestScore - average; // difference shows how my the highest score differs from the average
  48.         cout << "Average score: " << average << "Difference between the highest score and average: " << difference << endl;
  49.  
  50.  
  51.         { cout << "Would you like to repeat? Type Y/y for yes. " << endl;
  52.         cin >> ans;
  53.         }
  54.     } while (ans == 'Y' || ans == 'y');
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement