Vector and Lists

Here's what I am trying to accomplish with this program :

Please write a program to use vector and list to store 10 integers in order (from smallest to largest). You need to find proper location using vector or list functions for each number added. Please do NOT use any sorting function.
a. Generate 1 random integer between -100 and 100 and display it on screen
b. Insert the number generated in step b into Vector and List
c. Display the contents of Vector and List after adding a number
d. Use loop structure to repeat step a-c 10 times.
For example, the output screen may display as following:
Number generated: 23
Vector: 23
List: 23
Number generated: -15
Vector: -15, 23
List: -15, 23
Number generated: 40
Vector: -15, 23, 40
List: -15, 23, 40
Number generated: -6
Vector: -15, -6, 23, 40
List: 15, -6, 23, 40
etc

Below is what I have so far and I am struggling with the remaining program. Any help would be appreciated. Thanks


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
int i;

srand(unsigned( time(0)));//random generator to generate 10 integers

for (i = 0; i < 10; ++i )
v.push_back( rand()%21 - 10 );
cout << "The numbers in the vector are: ";
for (i = 0; i<10; i++)
cout << v[i] << ' ';
cout << endl;
return 0;
}
There's a library called <list> as well. Might wanna start with that.

http://www.cplusplus.com/reference/list/list/push_back/
Topic archived. No new replies allowed.