### Finding Min/Max (loop)

Write a loop to do the following:
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

#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 "}"

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include 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(maxjumo[a]) { min=jumo[a]; } } cout<<"Maximum value is "<

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.