| | |
min and max values
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2005
Posts: 5
Reputation:
Solved Threads: 0
I know you don't do homework for people. But I'm not really sure where else to turn to, because my online tutor for my class isn't really helping. I'll show you the code I have. (I worked about 6 hours on it, honestly. I'm really really bad at this.) If you don't want to help, I understand.
The problem is: In a gymnastics or diving competition, each contestant's score is calculated by dropping the lowest and highest scores received and then adding the remaining scores. Write a program that allows the user to enter eight judges' scores and outputs the points received by the contestant. Format your output with two decimal places.
Here is what I have: (Please don't make fun of the fact that it just took me 6 freaking hours to do this.) My error is with the max and min element. I've never used that before. In fact, I just found them at the back of the book. We haven't actually gotten to algorithms. I couldn't think of anything else to use to find the highest and lowest scores. Thanks so so much if anyone replies!!!!!!
The problem is: In a gymnastics or diving competition, each contestant's score is calculated by dropping the lowest and highest scores received and then adding the remaining scores. Write a program that allows the user to enter eight judges' scores and outputs the points received by the contestant. Format your output with two decimal places.
Here is what I have: (Please don't make fun of the fact that it just took me 6 freaking hours to do this.) My error is with the max and min element. I've never used that before. In fact, I just found them at the back of the book. We haven't actually gotten to algorithms. I couldn't think of anything else to use to find the highest and lowest scores. Thanks so so much if anyone replies!!!!!!
C++ Syntax (Toggle Plain Text)
// Gymnastics Competition Problem // Laura Ade #include <iostream> using std::cout; using std::endl; using std::cin; using std::fixed; #include <iomanip> using std::setprecision; #include <algorithm> // algorithm definitions using std::max_element; using std::min_element; int main() { double score; // individual judge's score double min_element; // lowest score double max_element; // highest score double subtotal; // includes min and max scores double final; // final score int scoreCounter; // number of scores to be entered next // Initialization Phase subtotal = 0; // initialize final scoreCounter = 1; // initialize loop counter // Processing Phase while ( scoreCounter <= 7 ) { // loop 8 times cout << "Enter individual judge's score: "; // prompt for input cin >> score; // read score from user subtotal = subtotal + score; // add score to subtotal scoreCounter = scoreCounter + 1; // add 1 to counter } // Termination Phase final = subtotal - max_element - min_element; // drop highest & lowest score // Display Result cout << "Final score is " << final << endl; return 0; // indicate program ended successfully
Last edited by Dave Sinkula; Nov 30th, 2005 at 12:24 am. Reason: Added [code][/code] tags.
•
•
Join Date: Jul 2005
Posts: 35
Reputation:
Solved Threads: 0
The code in BLUE it is where i change/add. The min_element and max_element is a function that return the maximum and minimum value.
<< moderator edit: added
// Gymnastics Competition Problem
// Laura Ade
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
#include <iomanip>
using std::setprecision;
#include <algorithm> // algorithm definitions
using std::max_element;
using std::min_element;
int main()
{
double score; // individual judge's score
double subtotal; // includes min and max scores
double final; // final score
int scoreCounter;// number of scores to be entered next
double array[7];]// create an array to hold the score enter by user
int array_size = 7;// the size of the array
subtotal = 0; // initialize final
scoreCounter = 1; // initialize loop counter
// Processing Phase
while ( scoreCounter <= 7 ){ // loop 8 times
cout << "Enter individual judge's score: "; // prompt for input
cin >> score; // read score from user
array[scoreCounter-1] = score;
subtotal = subtotal + score; // add score to subtotal
scoreCounter = scoreCounter + 1; // add 1 to counter
}
// Termination Phase
double max = *max_element( array, array+array_size);
double min =*min_element( array, array+array_size);
final = subtotal - max - min;// drop highest & lowest score
// Display Result
cout << "Final score is " << final << endl;
return 0; // indicate program ended successfully
}[code][/code] tags >> Last edited by Dave Sinkula; Nov 30th, 2005 at 10:42 am.
![]() |
Similar Threads
- difference between min heap and max heap... (C)
- min/max of a mixed type list (Python)
- Max and Min values from a group of numbers (C++)
Other Threads in the C++ Forum
- Previous Thread: need help fast
- Next Thread: Standard template library
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





