min and max values

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2005
Posts: 5
Reputation: ban26ana is an unknown quantity at this point 
Solved Threads: 0
ban26ana ban26ana is offline Offline
Newbie Poster

min and max values

 
0
  #1
Nov 30th, 2005
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!!!!!!


  1. // Gymnastics Competition Problem
  2. // Laura Ade
  3.  
  4. #include <iostream>
  5.  
  6. using std::cout;
  7. using std::endl;
  8. using std::cin;
  9. using std::fixed;
  10.  
  11.  
  12. #include <iomanip>
  13.  
  14. using std::setprecision;
  15.  
  16.  
  17. #include <algorithm> // algorithm definitions
  18.  
  19. using std::max_element;
  20. using std::min_element;
  21.  
  22. int main()
  23. {
  24. double score; // individual judge's score
  25. double min_element; // lowest score
  26. double max_element; // highest score
  27. double subtotal; // includes min and max scores
  28. double final; // final score
  29. int scoreCounter; // number of scores to be entered next
  30.  
  31. // Initialization Phase
  32. subtotal = 0; // initialize final
  33. scoreCounter = 1; // initialize loop counter
  34.  
  35. // Processing Phase
  36. while ( scoreCounter <= 7 ) { // loop 8 times
  37. cout << "Enter individual judge's score: "; // prompt for input
  38. cin >> score; // read score from user
  39. subtotal = subtotal + score; // add score to subtotal
  40. scoreCounter = scoreCounter + 1; // add 1 to counter
  41. }
  42.  
  43. // Termination Phase
  44. final = subtotal - max_element - min_element; // drop highest & lowest score
  45.  
  46. // Display Result
  47. cout << "Final score is " << final << endl;
  48.  
  49. return 0; // indicate program ended successfully
Last edited by Dave Sinkula; Nov 30th, 2005 at 12:24 am. Reason: Added [code][/code] tags.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 35
Reputation: k_en is an unknown quantity at this point 
Solved Threads: 0
k_en k_en is offline Offline
Light Poster

Re: min and max values

 
0
  #2
Nov 30th, 2005
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.


// 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

}
<< moderator edit: added [code][/code] tags >>
Last edited by Dave Sinkula; Nov 30th, 2005 at 10:42 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 5
Reputation: ban26ana is an unknown quantity at this point 
Solved Threads: 0
ban26ana ban26ana is offline Offline
Newbie Poster

Re: min and max values

 
0
  #3
Nov 30th, 2005
Thank you so much! There are still a couple of errors in there, but I worked on it for about an hour and fixed them. Thank you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC