# Thread: calculating maximum and minimum values for a basic C++ program

1. ## calculating maximum and minimum values for a basic C++ program

I'm having trouble creating a program that has 4 input values and from that calculating the minimum and maximum values, for example if you had 1, 4, 19, 5, the maximum value for this data set would be 19 and the minimum value would be 1, I'm getting stuck on the if statement, how would I construct a better one including all variables?

This is what I've got so far:

float min, max(float a, b, c, d)
void main ( ) {
cout<<"insert 4 #'s \n";
cin>>a>>b>>c>>d;
if max(a,b,c,d == 1);
cout<<d, "_"<<c, "_" <<b, "_"<<a;
else if max(a, b, c, d) == 2)
cout<<"maximum value";
cout << " \n" ;
cout<<"insert 4#'s \n";
cin>>a>>b>>c>>d;
if min(a, b, c, d ==3)
cout<<a, "_"<<b, "_" <<c, "_"<<d;
else if min(a, b, c, d) == 4)
cout<<d, "_"<<c, "_" <<b, "_"<<a;
else
cout<<"minimum value";
}

what should I do?

2. This is not the complete way to do it. It does ask for input and it sorts 2 groups of 2. But its a start to making it easier. Ill try and change it because now it only sorts it in two groups of two. Try it out though

Code:
```#include <iostream>
#include <conio.h>

using namespace std;

int main()

{

void order(int*, int*);//prototype
int n1,n2,n3,n4;
cout <<"Enter first number"<<endl;
cin >>n1;
cout <<"Enter second number"<<endl;
cin >>n2;
cout <<"Enter third number"<<endl;
cin >>n3;
cout <<"Enter fourth number"<<endl;
cin >>n4;

cout<< "Before sort"<<endl;
cout<< "a ="<<n1<<endl;//before sort
cout<< "b ="<<n2<<endl;
cout<< "c ="<<n3<<endl;
cout<< "d ="<<n4<<endl;

order(&n1,&n2); //function call
order(&n3,&n4);

cout <<"After Sort"<<endl;
cout<< "a ="<<n1<<endl;//after sort
cout<< "b ="<<n2<<endl;
cout<< "c ="<<n3<<endl;
cout<< "d ="<<n4<<endl;

getch();
return 0;
}

void order(int* numb1, int* numb2) // swawp numbers
{
if(*numb1 > *numb2)
{
int temp = *numb1;
*numb1 = *numb2;
*numb2 = temp;
}
}```

3. Code:
```void max(int *arr, int size)
{
int i;
int min, max;

min = arr[0];
max = arr[0];
for(i = 1; i < size; i++)
{
if(arr[i] < min)
min = arr[i];
if(arr[i] > max)
max = arr[i];
}
cout << "max = " << max << endl << "min = " << min << endl;
}```