Vector code help

I am new to c++ and I trying to write a code using vectors to display numbers ,in between 10 and 101, received from the user. The problem i'm having is creating my main function.

heres what I have so far
Header:
1
2
3
4
5
6
7
8
9
10
  #include <vector>
#include <iostream>
using namespace std;

class Vector
{
public:
    void fillVector(vector<int&> vector);
    void printVector(const Vector(int&));
};


my functions:

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
#include "Vectors.h"
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;




                
                
void Vector::fillVector(vector<int&> newMyVector )
{
    cout << "Enter integers inbetween 10 and 101, type -1 to quit.";
    int input;
    cin >> input;
    
    while(input != -1){
        if (input >= 10 && input <= 101 ){
            newMyVector.push_back(input);
            cin >> input;
        }
        
        else {
            cout << input << "Please enter a valid number. " << endl;
        }
    }
}

void Vector:: printVector(const vector<int>& newMyVector){
    cout << "Vector: ";
    for (unsigned int i=0; i<newMyVector.size(); i++){
        cout << newMyVector[i] << " ";
    }
    cout << endl;
}


Main:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "Vectors.h"
#include <iostream>
#include <vector>
using namespace std;


int main()

{
    Vector MyVector;
    MyVector.fillVector()
    
}


the problem is in the main. I dont know what to put after MyVector.fillVector() so it will call back to the class "Vector" properly.
In your main() you don't pass a parameter to Vector::fillVector(), even tho the prototype says it needs one of type "vector<int&>". It appears you meant to put "vector<int>&" instead. The former means pass by value a vector whose contained-type is "int&" (which is also a compiler error as containers cannot have reference types as they contained type). The latter means accept a vector by reference, whose contained-type is "int". Don't forget to correct both your prototype and function definition!

Also your "Vector" doesn't appear to really be gaining you anything in this program, as you just populate/display a different object. I'd recommend scrapping it entirely, making your fillVector() and printVector() functions be global and still have that parameter.
Topic archived. No new replies allowed.