Finding Min/Max (loop)

Write a loop to do the following:
1. Read in 10 integers.
2. Find the maximum value.
3. Find the minimum value.

Output Display:

Enter 10 integers: 2 34 65 13 84 76 55 19 1 25
Maximum value is 84
Minimum value is 1


my code is error so please help me.

#include <iostream>
using namespace std;

int main()
{
int jumo[] = {1,2,3,4,5,6,7,8,9,10};
int max,min,a;

cout<<"Enter 10 integers: ";
for (int a=0;a<10;a++);
{
cin>>jumo[a];
}


max = jumo[0];
min = jumo[0];

for (int a=1;a<10;a++)
{
if(max<jumo[a])
{
max=jumo[a];
}
else if (min>jumo[a])
{
min=jumo[a];
}

cout<<"Maximum value is "<<max<<endl;
cout<<"Minumum value is "<<min<<endl;

system("pause");
return 0;
}
Using code tags will show us the formating of your code.
http://www.cplusplus.com/articles/z13hAqkS/

In this case after formatting your code it's easy to see where you left out a "}"

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
#include <iostream>
using namespace std;

int main()
{
int jumo[] = {1,2,3,4,5,6,7,8,9,10};
int max,min,a;

cout<<"Enter 10 integers: ";

for (int a=0;a<10;a++);
	{
	cin>>jumo[a];
	}


max = jumo[0];
min = jumo[0];

for (int a=1;a<10;a++)
	{
		if(max<jumo[a])
		{
		max=jumo[a];
		}
		else if (min>jumo[a])
		{
		min=jumo[a];
		}
	}
	cout<<"Maximum value is "<<max<<endl;
cout<<"Minumum value is "<<min<<endl;

// system("pause");
return 0;
}


Your code mostly works but I did find errors that I'll leave up to you on how to fix.




// Max value 10 but that wasn't used.
c:\temp>test123
Enter 10 integers: 1 2 3 4 5 6 7 8 9
Maximum value is 10
Minumum value is 1

// Max and Min values incorrect
c:\temp>test123
Enter 10 integers: 9 8 7 6 5 4 3 2 1
Maximum value is 10
Minumum value is 2

// Max value incorrect
c:\temp>test123
Enter 10 integers: 0 9 8 7 6 5 4 32 1
Maximum value is 10
Minumum value is 0

Last edited on
Topic archived. No new replies allowed.