Having problems with this code...

Fill even/odd vectors anmd transfer to a 2-D Array
Purpose: Input numbers and segregate them by placing their values into even or odd vectors based upon their value being even or odd. Then fill a 2-D Array with the first column containing the contents of the even vector and the second Column containingthe odd vector. Output the result and display the content of the vectors and array.

I'm running into the problem where I can't get the columns to be seperated. I'm able to get 1-9 in the same row. Any help? Here's what I got so far


/*
* File: main.cpp
* Author: YOUR NAME HERE
* Created on DATE AND TIME HERE
* Purpose: Even, Odd Vectors and Array Columns Even, Odd
* Note: Check out content of Sample conditions in Hacker Rank
* Input size of integer array, then array, output columns of Even, Odd
* Vectors then Even, Odd 2-D Array
*/

//System Libraries Here
#include <iostream>//cin,cout
#include <vector> //vectors<>
#include <iomanip> //Format setw(),right

using namespace std;

//User Libraries Here

//Global Constants Only, No Global Variables
//Allowed like PI, e, Gravity, conversions, array dimensions necessary
const int COLMAX=2;//Only 2 columns needed, even and odd

//Function Prototypes Here
void read(vector<int> &, vector<int> &);
void copy(vector<int>, vector<int>,int [][COLMAX]);
void printVec(vector<int>, vector<int>,int);//int n is the format setw(n)
void printAry(const int [][COLMAX],int,int,int);

//Program Execution Begins Here
int main(int argc, char** argv) {
//Declare all Variables Here
const int ROW=80; //No more than 80 rows
int array[ROW][COLMAX]; //Really, just an 80x2 array, even vs. odd
vector<int> even(0),odd(0); //Declare even,odd vectors

//Input data and place even in one vector odd in the other
read(even,odd);

//Now output the content of the vectors
setw(10);
printVec(even,odd,10); //Input even, odd vectors with setw(10);

//Copy the vectors into the 2 dimensional array
//copy(even,odd,array);

//Now output the content of the array
setw(10);
//prntAry(array,even.size(),odd.size(),10);//Same format as even/odd vectors

//Exit
return 0;
}
void read(vector<int> & even, vector<int> & odd){

int n;

cin >> n;
int input = 0;

for (int i = 0; i < n; i++)
{
cin >> input;
if (input%2==1){
odd.push_back(input);
}
if (input%2==0){
even.push_back(input);
}
}


}void printVec(vector<int> even, vector<int> odd,int set){
for (int x=0; x<even.size(); x++){
cout << fixed << showpoint;
cout << left << setw(10) << even[x] <<endl;
}

}


Format your code with the <> button when you edit your post, and repaste your code.

Firstly there are a lot of questionable features about your code, I recommend you clean up unused function parameters and variables / printing using std::fixed when you are only printing integers / blocks of dead code.

Using namespace std is OK most of the time, but when you start using something as vague rarely as used as fixed, it could make people much more confused reading your code. I would recommend only making cout, cin, endl and vector used.

Lastly, you don't even print the odd row at all, your printVec also copies the 2 arrays every time you call it, and you don't handle the case where one of the lists are longer than each other.

You need the toggle setw between the odd and even.
Topic archived. No new replies allowed.