|
Finding and rranging numbers
I am supposed to find 7 numbers between 1-10 and then find the smallest(already done) and largest(already done) and then display the middle 5 numbers from lowest to highest in a line. I am currently stuck on this, I have tried many ways. Can someone help, please?
# include <iostream.h>
# include <iomanip.h>
#include <ctype.h>
#include <stdlib.h>
using namespace std;
void getScores();
float findFirst(float,float,float,float,float,float,float);
float findLast(float,float,float,float,float,float,float);
float totalScore(float,float,float,float,float,float,float,float);
int main ()
{
void getScores();
float score1,score2,score3,score4,score5,score6,score7,totalscore=0;
float firstlowest=0;
float lastlargest=0;
float midonelowest, midtwo, midthree, midfour, midfive=0;
cout<<"Enter the first score: ";
cin >> score1;
while (score1<0||score1>10)
{
cout << "Wrong number, please try again: ";
cin >> score1;
}
cout <<"Enter the second score: ";
cin >> score2;
while (score2<0||score2>10)
{
cout << "Wrong number, please try again: ";
cin >> score2;
}
cout <<"Enter the third score: ";
cin >> score3;
while (score3<0||score3>10)
{
cout << "Wrong number, please try again: ";
cin >> score3;
}
cout<<"Enter the fourth score: ";
cin >> score4;
while (score4<0||score4>10)
{
cout << "Wrong number, please try again: ";
cin >> score4;
}
cout <<"Enter the fifth score: ";
cin >> score5;
while (score5<0||score5>10)
{
cout << "Wrong number, please try again: ";
cin >> score5;
}
cout <<"Enter the sixth score: ";
cin >> score6;
while (score6<0||score6>10)
{
cout << "Wrong number, please try again: ";
cin >> score6;
}
cout <<"Enter the seventh score: ";
cin >> score7;
while (score7<0||score7>10)
{
cout << "Wrong number, please try again: ";
cin >> score7;
}
totalscore= totalScore(score1,score2,score3,score4,score5,score6,score7,totalscore);
cout << "Your total score is "<<totalscore;
firstlowest = findFirst(score1,score2,score4,score4,score5,score6,score7);
cout << "\nYour lowest number is: " << firstlowest;
lastlargest = findLast(score1,score2,score4,score4,score5,score6,score7);
cout << "\nYour largest number is: " <<lastlargest<<endl;
cin >> lastlargest;
return 0;
}
float totalScore(float num1,float num2,float num3,float num4,float num5,float num6, float num7, float totalscore)
{
totalscore = num1+num2+num3+num4+num5+num6+num7;
return totalscore;
}
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;
}
|