#include <iostream>
#include <vector>
using namespace std;
int n;
void fill_progressive(vector<int>v1)
{
for(int i=1; i<=n; i++)
{
v1[i]=i;
}
}
void print_vector(vector<int>v1)
{
for(int i=1; i<=n; i++)
{
cout<<v1[i]<<", ";
}
cout<<"\n";
}
int main()
{
cin>>n;
vector<int> v1(n);
fill_progressive(v1);
print_vector(v1);
return 0;
}
So the main goal of my program is to take a user input and make a vector the size of the user input. I want the vector to contain rising numbers from 1 to n (in: 4 ; out: 1, 2, 3, 4,).
The vector has to be then printed out in order.
I've spend way too much time on making this program work and it does if the 'for' loops are in the main function, however when I use the void functions the program output is 0, 0, 0, 0, 5, (given that the input was 5).
Is there anything I can do to fix that or do I do I have to start from the beginning.
I hope there's a solution to my problem and I'm going to be very grateful if you bother helping me out.