Help!!!
I'm trying to eliminate the highest and lowest number out of 5 inputs then get the average of the remaining 3 inputs...
In some instances, it gives me incorrect average..
(We are not suppose to use arrays yet)
Here's my code:
#include <iostream>
using namespace std;
void getData(double& input1, double& input2, double& input3, double& input4, double& input5);
//Ask the user to input numbers
void calcscore(double& num1, double& num2, double& num3, double& num4, double& num5);
//should calculate and display the average of the 3 remaining numbers
int main()
{
double score1, score2, score3, score4, score5;
getData(score1, score2, score3, score4, score5);
calcscore(score1, score2, score3, score4, score5);
}
void getData(double& input1, double& input2, double& input3, double& input4, double& input5)
{
cout<<"Input 5 numbers : \n";
cin>> input1
>> input2
>> input3
>> input4
>> input5;
}
void calcscore(double& num1, double& num2, double& num3, double& num4, double& num5)
{
if (0 > num2&&num3&&num1&&num5&&num4)
{
cout<<"Error! Please enter numbers between 0 to 10 only" ;
cout<<"\n\n\n";
}
else if (num1 > num2&&num3&&num4 > num5)
{
cout<<"Average: "<<(num2 + num3 + num4)/3 ;
cout<<"\n\n\n";
}
else if (num2 > num1&&num3&&num4 > num5)
{
cout<<"Average: "<<(num1 + num3 + num4)/3 ;
cout<<"\n\n\n";
}
else if (num3 > num1&&num2&&num4 > num5)
{
cout<<"Average: "<<(num1 + num2 + num4)/3 ;
cout<<"\n\n\n";
}
else if (num4 > num1&&num2&&num3 > num5)
{
cout<<"Average: "<<(num1 + num2 + num3)/3 ;
cout<<"\n\n\n";
}
else if (num5 > num4&&num2&&num3 > num1)
{
cout<<"Average: "<<(num4 + num2 + num3)/3 ;
cout<<"\n\n\n";
}
else if (num1 > num5&&num2&&num3 > num4)
{
cout<<"Average: "<<(num5 + num2 + num3)/3 ;
cout<<"\n\n\n";
}
else if (num2 > num5&&num1&&num3 > num4)
{
cout<<"Average: "<<(num5 + num1 + num3)/3 ;
cout<<"\n\n\n";
}
else if (num3 > num5&&num2&&num1 > num4)
{
cout<<"Average: "<<(num5 + num2 + num1)/3 ;
cout<<"\n\n\n";
}
else if (num5 > num1&&num2&&num3 > num4)
{
cout<<"Average: "<<(num1 + num2 + num3)/3 ;
cout<<"\n\n\n";
}
else if (num4 > num1&&num2&&num5 > num3)
{
cout<<"Average: "<<(num1 + num2 + num5)/3 ;
cout<<"\n\n\n";
}
else if (num1 > num4&&num2&&num5 > num3)
{
cout<<"Average: "<<(num4 + num2 + num5)/3 ;
cout<<"\n\n\n";
}
else if (num2 > num4&&num1&&num5 > num3)
{
cout<<"Average: "<<(num4 + num1 + num5)/3 ;
cout<<"\n\n\n";
}
else if (num4 > num2&&num1&&num5 > num3)
{
cout<<"Average: "<<(num2 + num1 + num5)/3 ;
cout<<"\n\n\n";
}
else if (num5 > num2&&num1&&num4 > num3)
{
cout<<"Average: "<<(num2 + num1 + num4)/3 ;
cout<<"\n\n\n";
}
else if (num3 > num4&&num1&&num5 > num2)
{
cout<<"Average: "<<(num4 + num1 + num5)/3 ;
cout<<"\n\n\n";
}
else if (num1 > num2&&num1&&num5 > num2)
{
cout<<"Average: "<<(num2 + num1 + num5)/3 ;
cout<<"\n\n\n";
}
else if (num3 > num4&&num1&&num5 > num2)
{
cout<<"Average: "<<(num4 + num1 + num5)/3 ;
cout<<"\n\n\n";
}
else if (num4 > num3&&num1&&num5 > num2)
{
cout<<"Average: "<<(num3 + num1 + num5)/3 ;
cout<<"\n\n\n";
}
else if (num5 > num3&&num1&&num4 > num2)
{
cout<<"Average: "<<(num3 + num1 + num4)/3 ;
cout<<"\n\n\n";
}
else if (num2 > num3&&num1&&num5 > num4)
{
cout<<"Average: "<<(num3 + num1 + num5)/3 ;
cout<<"\n\n\n";
}
}