Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have 5 values and am trying to find the median without using arrays. If i plugged 1 2 3 4 5 my meadian is

I have 5 values and am trying to find the median without using arrays. If i plugged 1 2 3 4 5 my meadian is coming out as 1 what is worng? C++

if ((val1 <= val2 && val1 <= val3 && val1 >= val4 && val1 >= val5) ||

(val1 <= val2 && val1 <= val4 && val1 >= val3 && val1 >= val5) ||

(val1 <= val2 && val1 <= val5 && val1 >= val3 && val1 >= val4) ||

(val1 <= val3 && val1 <= val4 && val1 >= val2 && val1 >= val5) ||

(val1 <= val3 && val1 <= val5 && val1 >= val2 && val1 >= val4) ||

(val1 <= val4 && val1 <= val5 && val1 <= val2 && val1 <= val3)) {

medianVal = val1;

}

else if ((val2 <= val1 && val2 <= val3 && val2 >= val4 && val2 >= val5) ||

(val2 <= val1 && val2 <= val4 && val2 >= val3 && val2 >= val5) ||

(val2 <= val1 && val2 <= val5 && val2 >= val3 && val2 >= val4) ||

(val2 <= val3 && val2 <= val4 && val2 >= val1 && val2 >= val5) ||

(val2 <= val3 && val2 <= val5 && val2 >= val1 && val2 >= val4) ||

(val2 <= val4 && val2 <= val5 && val2 <= val1 && val2 <= val3)) {

medianVal = val2;

}

else if ((val3 <= val1 && val3 <= val2 && val3 >= val4 && val3 >= val5) ||

(val3 <= val1 && val3 <= val4 && val3 >= val2 && val3 >= val5) ||

(val3 <= val1 && val3 <= val5 && val3 >= val2 && val3 >= val4) ||

(val3 <= val2 && val3 <= val4 && val3 >= val1 && val3 >= val5) ||

(val3 <= val2 && val3 <= val5 && val3 >= val1 && val3 >= val4) ||

(val3 <= val4 && val3 <= val5 && val3 <= val1 && val3 <= val2)) {

medianVal = val3;

}

else if ((val4 <= val1 && val4 <= val2 && val4 >= val3 && val4 >= val5) ||

(val4 <= val1 && val4 <= val3 && val4 >= val2 && val4 >= val5) ||

(val4 <= val1 && val4 <= val5 && val4 >= val2 && val4 >= val3) ||

(val4 <= val2 && val4 <= val3 && val4 >= val1 && val4 >= val5) ||

(val4 <= val2 && val4 <= val5 && val4 >= val1 && val4 >= val3) ||

(val4 <= val3 && val4 <= val5 && val4 <= val1 && val4 <= val2)) {

medianVal = val4;

} else {

medianVal = val5;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions

Question

4. Devise an interview strategy from the interviewers point of view

Answered: 1 week ago