Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. //PART 1//
  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 the number of students: " << endl;
  16.         cin >> numStudents;
  17.         /*cout << "Enter students name";
  18.         cin >> studentName;
  19.  
  20.         cout << "Enter students score";
  21.         cin >> score;*/
  22.  
  23.  
  24.  
  25.         for (int i = 0; i < numStudents; i++)
  26.         { // begin for loop
  27.             cout << "Enter students name:" << endl;
  28.             cin >> studentName;
  29.             cout << "Enter score:" << endl;
  30.             cin >> score;
  31.  
  32.             //add score to total score to calculate the average
  33.             totalscore = totalscore + score;
  34.  
  35.             // highest score will be equal to score if score is greater than highest score
  36.             // if if statement is true it must store the studentname of highest score
  37.             if (score > highestScore)
  38.             {
  39.                 highestScore = score;
  40.                 highstudent = studentName;
  41.  
  42.             }
  43.             //else
  44.             cout << "Student with the highest score: " << highstudent << " Score: " << highestScore << endl;
  45.  
  46.  
  47.         }//for loop ends
  48.  
  49.         average = totalscore / numStudents;
  50.         difference = highestScore - average; // difference shows how my the highest score differs from the average
  51.         cout << "The average is " << average << "The difference between the highest score and average is " << difference << endl;
  52.  
  53.  
  54.         { cout << "Type Y/y to repeat." << endl;
  55.         cin >> ans;
  56.         }
  57.     } while (ans == 'Y' || ans == 'y');
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement