A container that holds 50 distinct integers has two ends: top and bottom. When an input integer matches one of the integers in the container, it is then moved to the top, and all the integers above the matched integer are moved down to fill the gap in the container (keeping the same order). When none of the integers in the container matches the input value, the bottom integer is discarded, the remaining integers are moved down to fill the gap (keeping the same order), and the input integer is inserted on top.
Write a C++ program to implement the above problem. Fill the initial container with distinct random integers in the range 0 to 99. Prompt the user to enter an integer, output the updated container. Repeat until the user enters a (any) negative value.
I got to generating the different numbers and output them but I don't know how to input an integer and compare it to those numbers.
If anyone has an idea let me know thanks.
Here is my code and the ouput:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int number;
srand((unsigned)time(0));
int random_integer;
for(int index=0; index<50; index++)
{
random_integer =(rand()%99)+0;
cout << random_integer << endl;
}
cout<< " Enter a number between 0 & 99: ";
cin>>number;
}
output:
93
85
63
42
77
70
56
45
69
54
57
39
63
21
47
30
37
9
64
94
73
57
78
36
54
1
50
76
54
43
62
48
27
24
88
5
94
43
50
65
96
7
3
60
26
50
88
64
58
53
Enter a number between 0 & 99: