I need to find the 5 middle numbers in the center(example: 2 3 4 5 6 7 8, the middle numbers are 3 4 5 6 7, remove+subtract largest and smallest numbers), I have tried many ways but have not succeeded. Can anyone please help me?

#include <iostream.h>
#include <iomanip.h>
#include <ctype.h>
#include <stdlib.h>

using namespace std;

float findMiddleOne(float,float,float,float,float,float,float);
float findFirst(float,float,float,float,float,float,float);
float findLast(float,float,float,float,float,float,float);

int main ()
	{
    string name;
	float score1,score2,score3,score4,score5,score6,score7,ttlscore=0;
	float firstlowest=0;
	float lastlargest=0;
	float difficulty;
	cout << "Enter the divers name: ";
    getline (cin,name);
    cout << "Enter the degree of difficulty for "<<name<<"'s dive: ";
    cin >> difficulty;
    		while (difficulty<1.2 ||difficulty>3.8)
			{
				cout << "Such difficulty does not exist, please try again: ";
				cin >> difficulty;
			}
	cout<<"Enter the seven judges' scores"<<endl;
	cout<<"First score: ";
	cin >> score1;
		while (score1<0||score1>10)
			{
				cout << "Wrong number, please try again: ";
				cin >> score1;
			}
	cout <<"Second score: ";
	cin >> score2;
		while (score2<0||score2>10)
			{
				cout << "Wrong number, please try again: ";
				cin >> score2;
			}
	cout <<"Third score: ";
	cin >> score3;
		while (score3<0||score3>10)
			{
				cout << "Wrong number, please try again: ";
				cin >> score3;
			}	
	cout<<"Fourth score: ";
	cin >> score4;
		while (score4<0||score4>10)
			{
				cout << "Wrong number, please try again: ";
				cin >> score4;
			}
	cout <<"Fifth score: ";
	cin >> score5;
		while (score5<0||score5>10)
			{
				cout << "Wrong number, please try again: ";
				cin >> score5;
			}
	cout <<"Sixth score: ";
	cin >> score6;
		while (score6<0||score6>10)
			{
				cout << "Wrong number, please try again: ";
				cin >> score6;
			}
	cout <<"Seventh score: ";
	cin >> score7;
		while (score7<0||score7>10)
			{
				cout << "Wrong number, please try again: ";
				cin >> score7;
			}
	firstlowest = findFirst(score1,score2,score4,score4,score5,score6,score7);
   	lastlargest = findLast(score1,score2,score4,score4,score5,score6,score7);
    ttlscore = (score1+score2+score3+score4+score5+score6+score7-firstlowest-lastlargest)*difficulty*0.6;
   	cout << name <<"'s total score is "<<ttlscore<<endl;

	cin >> ttlscore;
    return 0;
    }
    
float findFirst(float mid1,float mid2,float mid3,float mid4,float mid5,float mid6, float mid7)
	{
	float firstlowest;
	firstlowest = mid1;
	            if (mid2 < firstlowest)
		           firstlowest=mid2;
                if (mid3 < firstlowest)
		           firstlowest=mid3;
                if (mid4 < firstlowest)
		           firstlowest=mid4;
                if (mid5 < firstlowest)
		           firstlowest=mid5;	
	            if (mid6 < firstlowest)
		           firstlowest=mid6;
                if (mid7 < firstlowest)
		           firstlowest=mid7;
	return firstlowest;
	}
float findLast(float midd1,float midd2,float midd3,float midd4,float midd5,float midd6, float midd7)
	{
	float lastlargest;
	lastlargest = midd1;
	            if (midd2 > lastlargest)
		           lastlargest=midd2;
	            if (midd3 > lastlargest)
		           lastlargest=midd3;
                if (midd4 > lastlargest)
		           lastlargest=midd4;
	            if (midd5 > lastlargest)
		           lastlargest=midd5;	
                if (midd6 > lastlargest)
		           lastlargest=midd6;
                if (midd7 > lastlargest)
		           lastlargest=midd7;
	return lastlargest;
	}

Recommended Answers

All 2 Replies

you want to work with arrays. First create an array of 5 integers int array[] = {1,2,3,4,5}; Now its simple. The middle three numbers are array[1], array[2], and array[3].

Next, to get the largest and smallest numbers, just create a loop and check each array element

int largest = array[1];
int smallest = array[1];
for(int i = 1; i < 4; i++)
{
   if( largest < array[i])
      largest = array[i];
  // now do the same test for smallest
}

Are the numbers in that array in order?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.