.............................................
Last edited on
...........................................
Last edited on
Give me the whole source.
.....................................................
Last edited on
......................................................
Last edited on
The main function has no idea what "vector" is.
There is no such thing as a 'Vector' in C++. If you want to use the vector standard library, you have to #include<vector>, and vector<int>x.
If you want to let the main function know what the function is, you have to do this.
1 2 3 4 5 6 7 8 9 10 11 12
|
void Vector();
int main()
{
// code
return 0;
}
void Vector()
{
// definition
}
|
Last edited on
..........................................................
Last edited on
......................................................................
Last edited on
....................................................................................
Last edited on
..................................................................................
Last edited on
A .cpp and header? Just put this in header file:
1 2 3 4 5 6 7
|
// whatever.h
#include <iostream>
#include <cstdlib>
void displayValue(int[], int);
void setValue(int[], int);
|
This in .cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
// Whatever.cpp
void setValue(int value[], int size)
{
for (int count = 0; count < size; count++)
{
cin >> value[count];
}
}
void displayValue(int value[], int size)
{
cout << "Vector a: ";
for (int count = 0; count < size; count++)
{
cout << value[count] << ' ';
}
cout << endl;
}
|
Your main will look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include "Whatever.h"
using namespace std;
int main()
{
int size;
int* value;
cout << "Input vector a: " << endl;
cin >> size;
value = new int [size];
setValue(value, size);
displayValue(value, size);
delete[] value;
return 0;
}
|
And that should get you passing grades.
Last edited on
..................................................................................
Last edited on
...............................................................
Last edited on
What? Why does it NEED to be that?
...............................................................
Last edited on
But why? I don't understand what you're saying. If it needs to be that then why isn't it that? You clearly already have the code you need.
Last edited on
........................................................................
Last edited on
........................................................................
Last edited on