Advertisement
hfxdesign

PFunc

Nov 14th, 2014
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. /*
  2. Name: Nickelis Jarvis
  3. Date: 11.13.14
  4. Program Name: Sinclair's Got Talent
  5. Description: Average judge scores and print winning contestant along with score.*/
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <string>
  10. #include <vector>
  11.  
  12.  
  13. int* findLowest(int* score, int size) {
  14.     int* lowest = score;
  15.     for (int i = 0; i < size; i++) {
  16.         if (*lowest > *score)
  17.             *lowest = *score;
  18.         score++;
  19.     }
  20.     return lowest;
  21. }
  22.  
  23. int* findHighest(int* score, int size) {
  24.     int* highest = score;
  25.     for (int i = 0; i < size; i++) {
  26.         if (*highest < *score)
  27.             *highest = *score;
  28.         score++;
  29.     }
  30.     return highest;
  31. }
  32.  
  33. double calcAvgScore(int *score, int size) {
  34.     double avg = 0;
  35.     for (int i = 0; i < size; i++) {
  36.         avg += score[i];
  37.     }
  38.     avg = (avg - (*findHighest(&score[0], size) + *findLowest(&score[0], size))) / (size - 2);
  39.     return avg;
  40. }
  41.  
  42.  
  43.  
  44. int main() {
  45.     std::vector<std::string> c_name;
  46.     std::vector<double> c_average;
  47.     int n = 0;
  48.     bool newContestant;
  49.  
  50.     do {
  51.         int c_score[5];
  52.         newContestant = false;
  53.         std::string name_temp;
  54.  
  55.         n = c_name.size();
  56.         c_average.push_back(double());
  57.  
  58.         std::cout << "Enter contestant name: "; {
  59.             std::cin >> name_temp;
  60.             if (name_temp != "Done"){
  61.                 c_name.push_back(name_temp);
  62.             }
  63.         }
  64.  
  65.         for (int i = 0; i < 5; i++) {
  66.             bool valid = false;
  67.  
  68.             while (!valid) {
  69.                 int score_temp;
  70.  
  71.                 std::cout << "Enter judge #" << i + 1 << "\'s score: ";
  72.                 std::cin >> score_temp;
  73.  
  74.                 if (score_temp >= 0 && score_temp <= 10) {
  75.                     c_score[i] = score_temp;
  76.                     valid = true;
  77.                 }
  78.                 else
  79.                     std::cout << "Invalid score, try again.\n" << std::endl;
  80.             }
  81.             if (c_score) {
  82.                 newContestant = true;
  83.             }
  84.         }
  85.         if (newContestant)
  86.             c_average.push_back(calcAvgScore(c_score, 5));
  87.     } while (newContestant);
  88.     //Finish code here.
  89.  
  90.     system("pause");
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement