rego
05-16-2007, 02:12 PM
Hi there,
wonder if anyone can help :)
here is my code
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <list>
using namespace std;
using std::list;
typedef list <int> IntList;
void DisplayList(IntList pipeline)
{
for (IntList::const_iterator i = pipeline.begin(); i != pipeline.end(); i++ )
{
cout << *i << " ";
}
}
void PrepList(IntList pipeline)
{
srand( time(NULL) );
int num;
for(int i = 0; i < 3; i++)
{
num = rand() % 7;
pipeline.push_back(num);
}
}
int main()
{
IntList pipeline;
PrepList(pipeline);
DisplayList(pipeline);// <<<<< NEED THIS TO PRINT THE LIST VALUES
system("PAUSE");
return 0;
}
I just need some one to point me in the right direction regarding how to change PrepList into a function which can return a <list> type for main() to print out the list (if that's even possible) or any way in which this can be done
To recap i need to be able to create a random list in a function and then display it in the main part of the program using a display function.
At the moment the PrepList function is of type void which is obviously wrong :)
Many Thanks!
Rego
wonder if anyone can help :)
here is my code
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <list>
using namespace std;
using std::list;
typedef list <int> IntList;
void DisplayList(IntList pipeline)
{
for (IntList::const_iterator i = pipeline.begin(); i != pipeline.end(); i++ )
{
cout << *i << " ";
}
}
void PrepList(IntList pipeline)
{
srand( time(NULL) );
int num;
for(int i = 0; i < 3; i++)
{
num = rand() % 7;
pipeline.push_back(num);
}
}
int main()
{
IntList pipeline;
PrepList(pipeline);
DisplayList(pipeline);// <<<<< NEED THIS TO PRINT THE LIST VALUES
system("PAUSE");
return 0;
}
I just need some one to point me in the right direction regarding how to change PrepList into a function which can return a <list> type for main() to print out the list (if that's even possible) or any way in which this can be done
To recap i need to be able to create a random list in a function and then display it in the main part of the program using a display function.
At the moment the PrepList function is of type void which is obviously wrong :)
Many Thanks!
Rego