Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Help with c++


jaekx
 Share

Recommended Posts

This is my code

```

// Vector.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include #include #include "time.h"

using namespace std;

void PrintVector(const std::vector &MyRand2 );

int _tmain(int argc, _TCHAR* argv[])

{

//Random number stuff

srand( time(NULL)); // this 'seeds' random number generator

// The modulus operator is used to manage or control the number

// Its the ramainded after dividing by the number (10) ans. 0-9

vector MyVector;

for(int i=0; i<20; i++)

{

MyVector.push_back(rand()%10);

}

PrintVector( MyVector );

system("pause");

return 0;

}

void PrintVector(const std::vector &MyRand2)

{

std::vector::const_iterator constIterator;

for( constIterator = MyRand2.begin(); constIterator != MyRand2.end(); constIterator++ )

{

cout << *constIterator << ' ';

}

}

```
this is my output

9 2 8 9 0 0 8 1 7 7 4 5 0 8 3 3 0 5 5 2

this is my desired output

9 2 8 9 0 0 8 1 7 7

4 5 0 8 3 3 0 5 5 2

I know this is probably god awfully simple, but I cant find where to place endl; effectively.
Link to comment
Share on other sites

```

void PrintVector(const std::vector &MyRand2)

{

int count = 0;

std::vector::const_iterator constIterator;

for( constIterator = MyRand2.begin(); constIterator != MyRand2.end(); constIterator++ )

{

if(count % 10 == 0)

{

printf("\n");

}

cout << *constIterator << ' ';

++count;

}

}

```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...