Using vectors to find the highest and lowest values

I am seeking some guidance as to where I went wrong with my program. I am supposed to write a program that lets a user input 10 integer values into a vector ad then have the highest and lowest values stored in the vector displayed. This needs be completed by using two return functions that take the vector in as a parameter and return the values. My program will execute but will crash after inputting the first value. Please help! Thank you in advance!



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
  
//find the highest and lowest values in a vector. 

#include <iostream>
#include <vector>
using namespace std;

int main ()
{
	vector<int> values; //numbers that are entered
	int count;
	
	//Ask for entry of numbers into the vector
		for (count= 0; count < 10; count++)
		{
			cout << "Please enter a number "
				<< (count + 1) << ": ";
				cin >> values[count];
		}
		
	int highest;
	
	highest = values[0];
	for (count = 1; count < 10; count++)
	{
		if (values[count] > highest)
			highest = values[count];
	}
	
	//display the highest number in the vector
	cout << "The highest number out of the ten entered is: " << 
          highest << endl;
	
	//determine the lowest number out of the ten entered
	
	int lowest;
	
	lowest = values[0];
	for (count = 1; count < 10; count++)
	{
		if (values[count] < lowest)
			lowest = values[count];
	}
	
	//display the lowest number in the vector
	cout << "The lowest number out of the ten entered is: " << 
          lowest << endl;
	
	return 0;
}
cin >> values[count];
Here your trying to access a vector of size 0. You need to either give the vector a size eg values.resize(10) or use the push_back() method
Thank you for your help!! :)
Topic archived. No new replies allowed.