C++ finding max value

Hello, i am trying to find the max value from a list of 10 values. here i have stored the double values for prices of items in numVal.There are 10 values in numVal i would like to find the max and min value of these numbers. getPrice(1) returns the ten double values. Any help is appretiated, thank you.
1
2
3
4
for(int i = 0; i < store.size(); i++) {

	double numVal = this->store[i].getPrice(1);
}
Last edited on
To get the min and max values from a vector of double values, you could:

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
vector<double> myVector;

double max;
double min;

for(unsigned int i=0;i<myVector.size();i++)
{
	if(i==0)
	{
		max=myVector[i];
		min=myVector[i];
	}
	
	else
	{
		if(myVector[i]>max)
		{
			max=myVector[i];
		}
		
		if(myVector[i]<min)
		{
			min=myVector[i];
		}
	}
}
Thank you this worked perfectly
Topic archived. No new replies allowed.