jaekx Posted November 18, 2012 Author Share Posted November 18, 2012 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 stuffsrand( 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-9vector 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 output9 2 8 9 0 0 8 1 7 7 4 5 0 8 3 3 0 5 5 2this is my desired output9 2 8 9 0 0 8 1 7 74 5 0 8 3 3 0 5 5 2I know this is probably god awfully simple, but I cant find where to place endl; effectively. Link to comment Share on other sites More sharing options...
Marsh Posted November 18, 2012 Share Posted November 18, 2012 ```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 More sharing options...
jaekx Posted November 18, 2012 Author Share Posted November 18, 2012 Time for a nap, lmao thanks Marshy Dearest! Link to comment Share on other sites More sharing options...
SawQuart Posted November 18, 2012 Share Posted November 18, 2012 Or you could just do if(i==10). It might be better for readability. It's just personal preference though. Link to comment Share on other sites More sharing options...
Marsh Posted November 19, 2012 Share Posted November 19, 2012 The difference is mine will do every 10 numbers. Yours will only do it once. Link to comment Share on other sites More sharing options...
SawQuart Posted November 19, 2012 Share Posted November 19, 2012 Oh I gotcha. I didn't read all of his source comments. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now