Assignment Help - Code Inside

Good day everyone, I have a c++ Assignment that says:
Write a program that will have two user defined functions. One function will allow the user to
enter integer values and store them in a vector and return the vector. The other function called
print will accept a vector and output the values stored in it.

I mus confess that I really d not know how to return a vector.

// My Code:

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
#include <iostream> 
#include <vector>  // Required Library                                
using namespace std;

storeVector () { // Declaring a vector function
	
	const int size = 5;	
	vector <int> data; // vector for sotring data of type int
	
	cout << "\tEnter 5 values. Press Enter key after typing a value."; // Initial title
	cout << endl << endl;
	
	// Loop for requesti data from user 5 times:
	for ( size_t i = 0; i < data.size(); i ++ ) {
		
		cout << "\tEnter any integer value: "; // requesting data from user
		data.push_back(i+1);
	}
	
	return data; // returning vector
}

int printVector ( vector <int> values ) {
	
	// Display the numbers in the vector:
	for ( int i = 0; i < values.values(); i++ ) {
		
		cout << values [i] << " ";
	}
	
	
}


int main () {
	
	const int size = 10;
	vector < int > vec (size, 10); // Test variable / all avlues on teh vector will be 10
	
	storeVector(); // Function Call
	printVector(vec); // Function Call
	
	return 0;
}


What I'm suppose to do is to return the vector. Whoever, I get the following errors:

27 9 C:\Users\Qonqueror\Documents\Programming I\Fall 2018\Assignment 1 q 4.cpp [Error] cannot convert 'std::vector<int>' to 'int' in return

I Would gladly appreciate your help.
Last edited on
Line 10 should be vector<int> storeVector() { // Declaring a vector function

Lines 38-40 can then be:
vector<int> vec = storeVector()
In the http://www.cplusplus.com/doc/tutorial/functions/
the first examples are a bit boring, for they return int.
Later on that page we see other types too. void, string ...

On line 23 you do declare that the function returns an int value.
Your compiler should warn that nowhere on lines 24-31 there is actual return.

On line 14 you iterate data.size() times.
Line 26 iterates values.values() times.
Does std::vector have method values()?

Lines 16 asks the user to give values, but the function does not read any input.
Thank to you all, I apologize for not replying earlier, I couldnt recover my email until now. Thanks for help.
Topic archived. No new replies allowed.