Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name: Nickelis Jarvis
- Date: 11.13.14
- Program Name: Sinclair's Got Talent
- Description: Average judge scores and print winning contestant along with score.*/
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <vector>
- int* findLowest(int* score, int size) {
- int* lowest = score;
- for (int i = 0; i < size; i++) {
- if (*lowest > *score)
- *lowest = *score;
- score++;
- }
- return lowest;
- }
- int* findHighest(int* score, int size) {
- int* highest = score;
- for (int i = 0; i < size; i++) {
- if (*highest < *score)
- *highest = *score;
- score++;
- }
- return highest;
- }
- double calcAvgScore(int *score, int size) {
- double avg = 0;
- for (int i = 0; i < size; i++) {
- avg += score[i];
- }
- avg = (avg - (*findHighest(&score[0], size) + *findLowest(&score[0], size))) / (size - 2);
- return avg;
- }
- int main() {
- std::vector<std::string> c_name;
- std::vector<double> c_average;
- int n = 0;
- bool newContestant;
- do {
- int c_score[5];
- newContestant = false;
- std::string name_temp;
- n = c_name.size();
- c_average.push_back(double());
- std::cout << "Enter contestant name: "; {
- std::cin >> name_temp;
- if (name_temp != "Done"){
- c_name.push_back(name_temp);
- }
- }
- for (int i = 0; i < 5; i++) {
- bool valid = false;
- while (!valid) {
- int score_temp;
- std::cout << "Enter judge #" << i + 1 << "\'s score: ";
- std::cin >> score_temp;
- if (score_temp >= 0 && score_temp <= 10) {
- c_score[i] = score_temp;
- valid = true;
- }
- else
- std::cout << "Invalid score, try again.\n" << std::endl;
- }
- if (c_score) {
- newContestant = true;
- }
- }
- if (newContestant)
- c_average.push_back(calcAvgScore(c_score, 5));
- } while (newContestant);
- //Finish code here.
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement