Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.19 KB | None | 0 0
  1. // PART B
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     char ans;
  11.     do
  12.     {
  13.         int numStudents, score, totalscore = 0, highestScore = 0, average, difference;
  14.         string studentName, highstudent; // string is used to get full name stored
  15.                                          // can not get full name store without use of underscore
  16.         cout << "Enter number of students:" << endl;
  17.         cin >> numStudents;
  18.  
  19.        
  20.         int i = 0;
  21.         while (i < numStudents)
  22.  
  23.             //for (int i = 0; i < numStudents; i++)
  24.         { // begin while loop
  25.             cout << "Enter the students name:" << endl;
  26.             cin >> studentName;
  27.             cout << "Enter score:" << endl;
  28.             cin >> score;
  29.  
  30.             //add score to total score to calculate the average
  31.             totalscore = totalscore + score;
  32.  
  33.             // highest score will be equal to score if score is greater than highest score
  34.             // if if statement is true it must store the studentname of highest score
  35.             if (score > highestScore)
  36.             {
  37.                 highestScore = score;
  38.                 highstudent = studentName;
  39.  
  40.             }
  41.             //else
  42.             cout << "The student with the highest score is " << highstudent << " with a score of " << highestScore << endl;
  43.  
  44.             i++; // this alternates the loop control variable
  45.         }//while loop ends
  46.  
  47.         average = totalscore / numStudents;
  48.         difference = highestScore - average; // difference shows how my the highest score differs from the average
  49.         cout << "Average score: " << average << "Difference between the highest score and average: " << difference << endl;
  50.  
  51.  
  52.         { cout << "Would you like to repeat? Type Y/y for yes. " << endl;
  53.         cin >> ans;
  54.         }
  55.     } while (ans == 'Y' || ans == 'y');
  56.  
  57. }
  58.  
  59. // PART A
  60.  
  61. #include "pch.h"
  62. #include <iostream>
  63. #include <string>
  64. using namespace std;
  65.  
  66. int main()
  67. {
  68.     char ans;
  69.     do
  70.     {
  71.         int numStudents, score, totalscore = 0, highestScore = 0, average, difference;
  72.         string studentName, highstudent; // string is used to get full name stored
  73.         // can not get full name store without use of underscore
  74.         cout << "Enter the number of students: " << endl;
  75.         cin >> numStudents;
  76.         /*cout << "Enter students name";
  77.         cin >> studentName;
  78.  
  79.         cout << "Enter students score";
  80.         cin >> score;*/
  81.  
  82.  
  83.  
  84.         for (int i = 0; i < numStudents; i++)
  85.         { // begin for loop
  86.             cout << "Enter students name:" << endl;
  87.             cin >> studentName;
  88.             cout << "Enter score:" << endl;
  89.             cin >> score;
  90.  
  91.             //add score to total score to calculate the average
  92.             totalscore = totalscore + score;
  93.  
  94.             // highest score will be equal to score if score is greater than highest score
  95.             // if if statement is true it must store the studentname of highest score
  96.             if (score > highestScore)
  97.             {
  98.                 highestScore = score;
  99.                 highstudent = studentName;
  100.  
  101.             }
  102.             //else
  103.             cout << "Student with the highest score: " << highstudent << " Score: " << highestScore << endl;
  104.  
  105.  
  106.         }//for loop ends
  107.  
  108.         average = totalscore / numStudents;
  109.         difference = highestScore - average; // difference shows how my the highest score differs from the average
  110.         cout << "The average is " << average << "The difference between the highest score and average is " << difference << endl;
  111.  
  112.  
  113.         { cout << "Type Y/y to repeat." << endl;
  114.         cin >> ans;
  115.         }
  116.     } while (ans == 'Y' || ans == 'y');
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement