Finding MIn and max values BUt ?

I was trying to make a program which would max and min values for five inputs >>

Bout i get a bug :: when i try to enter 1 , 2 , 3 , 4 ,5 it gave me max = 5 and min = 4 why and when i enter 5 4 3 2 1 it gives me right ans wer ;


#include <iostream>

using namespace std;

int main () {

//lets make a program for MAX and min valus

int a, b ,c ,d ,e ;

cout << "enter a number ";
cin >> a ;

cout << "enter ";
cin >> b ;

cout << "enter it again";
cin >> c;

cout << "enter pls";
cin >> d ;

cout << "last one ";
cin >> e ;





int max , min ;






max = a ;



if (b > max)

max = b ;

if (c> max)

max = c ;

if (d > max)

max = d ;

if (e > max)

max = e ;

//for mini
min = a ;

if (b < min)

min = b ;

if (c < min )

min = c ;


if (d < min);

min = d ;

if(e < min )

min = e ;



cout << "\n\nthe maximum value is "<<max<< endl ;


cout << "\n\n THe mimimum value is "<<min<< endl ;


return 0; }
use code tags.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>

using namespace std;

int main () {

//lets make a program for MAX and min valus 

int a, b ,c ,d ,e ;

cout << "enter a number ";
cin >> a ;

cout << "enter ";
cin >> b ;

cout << "enter it again";
cin >> c;

cout << "enter pls";
cin >> d ;

cout << "last one ";
cin >> e ;





int max , min ; 






max = a ;



if (b > max) 

max = b ;

if (c> max)

max = c ;

if (d > max)

max = d ;

if (e > max)

max = e ;

//for mini
min = a ;

if (b < min)

min = b ;

if (c < min )

min = c ;


if (d < min);

min = d ;

if(e < min )

min = e ; 



cout << "\n\nthe maximum value is "<<max<< endl ;


cout << "\n\n THe mimimum value is "<<min<< endl ;


return 0;	}
Problem is with line 69. Remove the semicolon after the if
You may want to store a,b,c,d,e in an array and find de max in a loop through the array, at least if you stil need them afterwards. If you don't need them consider a max macro or function during input.

#define max(a, b) (((a) > (b)) ? (a) : (b))
Topic archived. No new replies allowed.