# how i want to find the max and min value in array?

Page 1 of 1

## 6 Replies - 2384 Views - Last Post: 24 December 2011 - 03:04 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=259918&amp;s=a3f21e22199705deabda822231b825eb&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 sisieablebeable

Reputation: 0
• Posts: 14
• Joined: 14-December 11

# how i want to find the max and min value in array?

Posted 14 December 2011 - 07:01 PM

```# include <iostream>

using namespace std;
//const int values = 30;

int main ()
{
int sum=0;
int num[5],max,min;
float average;

cout << "Please enter 5 numbers to get the sum : \n ";

for (int i=0; i<5; i++)
{
cin >> num[i];
}

int j=0;
while (j<5)
{
sum += num[j];
j++;
}

cout << "Sum : " << sum<<endl;

average = sum/5;
cout<<"average :"<<average<<endl;

for (int i=0; i<5; i++)
{
if (i[j]< max)  //something wrong with this

max = i[j];

}
else if (j[i]<min)
{
min = j[i];

cout<<"max:"<<max<<endl;
cout<<"min:"<<min<<endl;
}
return 0;
}
```

This post has been edited by jimblumberg: 14 December 2011 - 07:02 PM
Reason for edit:: Added missing Code Tags, Please learn to use them.:code:

Is This A Good Question/Topic? 0

## Replies To: how i want to find the max and min value in array?

### #2 tlhIn`toq

• Xamarin Cert. Dev.

Reputation: 6528
• Posts: 14,439
• Joined: 02-June 10

## Re: how i want to find the max and min value in array?

Posted 14 December 2011 - 07:04 PM

HINT:

Your comparison on line 33 and on 38 are using the same operator of less than.

Since one is trying to find the min and one is trying to find the max then both comparisons can't be the same, can they?

### #3 sisieablebeable

Reputation: 0
• Posts: 14
• Joined: 14-December 11

## Re: how i want to find the max and min value in array?

Posted 22 December 2011 - 11:20 PM

tlhIn`toq, on 14 December 2011 - 07:04 PM, said:

HINT:

Your comparison on line 33 and on 38 are using the same operator of less than.

Since one is trying to find the min and one is trying to find the max then both comparisons can't be the same, can they?

ok..thanks for helping

### #4 sisieablebeable

Reputation: 0
• Posts: 14
• Joined: 14-December 11

## Re: how i want to find the max and min value in array?

Posted 22 December 2011 - 11:25 PM

how i can improve my coding..?
and please show me the best way to learn and study C++..

### #5 HariC

Reputation: 2
• Posts: 11
• Joined: 16-November 11

## Re: how i want to find the max and min value in array?

Posted 23 December 2011 - 01:34 AM

If you are a beginner, just try to learn all the concepts of basic and some in depth concepts of C++ using the following links:

www.exforsys.com
www.cplusplus.com

Learn the language from these websites which are more useful.

### #6 sisieablebeable

Reputation: 0
• Posts: 14
• Joined: 14-December 11

## Re: how i want to find the max and min value in array?

Posted 24 December 2011 - 09:20 AM

thanks so much haRIC

### #7 vividexstance

• Tiocfaidh ár lá

Reputation: 792
• Posts: 2,873
• Joined: 31-December 10

## Re: how i want to find the max and min value in array?

Posted 24 December 2011 - 03:04 PM

Or you could look at the tutorials ON THIS SITE. Don't get me wrong, cplusplus.com is a good C++ reference site.