How to find maximum value

If a user inputs five values... How to find maximum value between those 5?

 
  cin>>a>>b>>c>>d>>e;

In this code we took 5 inputs, Now we have to find maximum value entered by user.
largest = max( { a, b, c, d, e } );
Last edited on
I have to do this only using loops. That's challenging...
Well, unless you put them into an array so that your loop cycles through the index of an array, any loop method would have to pick them out of an initialiser list. Or you would have to read them one by one. Take your pick.

It's not challenging ... have a go.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int a,b,c,d,e,max;
cin>>a;
max=a;
cin>>b;
if(b>max)
max=b;
cin>>c;
if(c>max)
max=c;
cin>>d;
if(d>max)
max=d;
cin>>e;
if(e>max)
max=e;
Last edited on
I thought you wanted to use loops?
Topic archived. No new replies allowed.