min and max

hello guys...

can you help with my assignment...my instructor asked me to program about min and max...the output must be like this.

enter no1 = 34
enter no2 = 23
enter no2 = 15

output:
15 is the min.
23 is the mid.
34 is the max

But if the user enter a number such as this.
enter no1 = 34 output:
enter no2 = 23 23 is the min.
enter no2 = 34 34 is the max.
What do you have so far?
this is the code I made.

#include <iostream>

using namespace std;

int main()

{
int n1;
int n2;
int n3;
int min;
int mid;
int max;
char a;

cout<<"Enter n1:";
cin>>n1;

cout<<"Enter n2:";
cin>>n2;

cout<<"Enter n3:";
cin>>n3;

cout<<endl;
cout<<endl;
cout<<"Results:"<<endl;

if(n1 <n2 && n1 < n3){
min = n1;
if(n2 < n3){
mid =n2;
max = n3;
}else{
mid =n3;
max=n2;

}
}else if (n2 < n1 && n2 < n3){
min =n2;
if(n1 < n3){
mid = n1;
max = n3;
}else{
mid =n3;
max = n1;

}
}else{
min = n3;
if(n1 < n2){
mid = n1;
max = n2;
}else{

mid = n2;
max = n1;


}


}


if (n1==n2){
max = n1;
min = n1;
}else if(n1==n3){
max = n1,n3;
min = n1,n3;



cout<<min<<"is the min\n";
cout<<mid<<"is the mid\n";
cout<<max<<"is the max\n";

}else{

cout<<min<<"is the min\n";
cout<<max<<"is the max\n";

}


system("pause");

}


I only have an output of :

15 is the min.
34 is the max.

but never in

15 is the min.
23 is the mid.
34 is the max.

yes I was trying to get the min and max bfore but now the min,mid and max will no longer appeared.
That code is awkward to read without using code tags.

Try having a look at:
http://www.cplusplus.com/reference/algorithm/min_element/
http://www.cplusplus.com/reference/algorithm/max_element/

and using an array to store your values.
your code shall work but this part has no use
if (n1==n2){
max = n1;
min = n1;
}else if(n1==n3){
max = n1,n3;
min = n1,n3;
i think it 'll work without it
Topic archived. No new replies allowed.