Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 7: Write a function that takes as input 3 numbers. The function will ret

ID: 641203 • Letter: P

Question

Problem 7: Write a function that takes as input 3 numbers. The function will return a Boolean value indicating whether the first parameter is less than the second, and the second is less than the third. In addition, if they are not in order, the function will change the values of the parameters so that the first parameter is the smallest of the three parameters, the third parameter is the largest of the three parameters, and the middle parameter is the value in the middle (or put the parameters in order). Now write a program that asks the user to input 3 separate numbers. It then prints out those three numbers. It then calls the function with those three numbers. If the function returns a Boolean value of false, it should then print out the three parameters, which have been modified within the function to now be in order.

Explanation / Answer

Run this program in DEV Cpp

#include<iostream>
#include<conio.h>
#include<stdlib.h>

using namespace std;
int z=1;

bool order(int a,int b,int c)
{
   int t;
   if(::z == 1)
   {
       if(a<b && b<c)
       {
           ::z++;
           return true;
       }
       else
       {
           ::z++;
           return false;
       }
   }
   if(a<b && a<c && b>c)
   {
       t=b;
       b=c;
       c=t;
   }
   if(c>a && c>b && a>b)
   {
       t=a;
       a=b;
       b=t;
   }
   if(b>a && b>c && a>c)
   {
       t=b;
       b=c;
       c=t;
       t=a;
       a=b;
       b=t;
   }
   if(b<a && b<c && a>c)
   {
       t=a;
       a=c;
       c=t;
       t=a;
       a=b;
       b=t;
   }
   if(a>b && a>c && b>c)
   {
       t=a;
       a=c;
       c=t;
   }
   cout<<"Now a,b,c are in order :"<<a<<" , "<<b<<" , "<<c<<endl;
   return 0;
}

int main()
{
   int a,b,c;
   bool x;
   cout<<"Enter the three value:";
   cin>>a>>b>>c;
   cout<<"You have entered "<<a<<" , "<<b<<" , "<<c<<endl;
   if(!order(a,b,c))
   {
       order(a,b,c);
   }
   getch();
   return 0;
}