Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PART 1//
- #include "pch.h"
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- char ans;
- do
- {
- int numStudents, score, totalscore = 0, highestScore = 0, average, difference;
- string studentName, highstudent; // string is used to get full name stored
- // can not get full name store without use of underscore
- cout << "Enter the number of students: " << endl;
- cin >> numStudents;
- /*cout << "Enter students name";
- cin >> studentName;
- cout << "Enter students score";
- cin >> score;*/
- for (int i = 0; i < numStudents; i++)
- { // begin for loop
- cout << "Enter students name:" << endl;
- cin >> studentName;
- cout << "Enter score:" << endl;
- cin >> score;
- //add score to total score to calculate the average
- totalscore = totalscore + score;
- // highest score will be equal to score if score is greater than highest score
- // if if statement is true it must store the studentname of highest score
- if (score > highestScore)
- {
- highestScore = score;
- highstudent = studentName;
- }
- //else
- cout << "Student with the highest score: " << highstudent << " Score: " << highestScore << endl;
- }//for loop ends
- average = totalscore / numStudents;
- difference = highestScore - average; // difference shows how my the highest score differs from the average
- cout << "The average is " << average << "The difference between the highest score and average is " << difference << endl;
- { cout << "Type Y/y to repeat." << endl;
- cin >> ans;
- }
- } while (ans == 'Y' || ans == 'y');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement