What I need to do is wait until 5 of a certain type of number appear consecutively and then begin a counter according to what numbers appear after. |
I think I understand what you mean, at least for your first statement about 5 numbers appearing consecutively.
I'll show you some code that partially does the first part of your problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <ctime>
#include <cstdlib> // needed for the rand and srand to work
#include <vector> // I used vectors to keep track of the values displayed
using namespace std;
int main()
{
time_t t;
time(&t);
srand(t);
vector<int> values;
for (int iIndex = 0; iIndex < 100; iIndex++)
{
int random_value = (rand() % 37 + 1);
cout << random_value << "\t";
values.push_back(random_value);
}
for (int jIndex = 0; jIndex < 100; jIndex++)
{
if ( values[jIndex] == values[jIndex + 1] && values[jIndex + 1] == values[jIndex + 2] )
{
// i.e. if a = b and b = c, then a = c
cout << "3 adjacent numbers repeat in this randomized output!" << endl;
}
}
}
|
(The "100" in the code is the number of random digits between 1 and 37 that are output.)
This code could probably be simplified, but it does the job. This code will display a message for each time 3 adjacent random integers are the same value. Add more && operators at line 27 to make the condition only make the message display if 4 adjacent numbers repeat, or 5, or beyond.
The program is currently limited by the 100, and it currently displays all 100 values (doesn't stop displaying even if there is a adjacent-value chain half-way through the output list). You also may have to run the program multiple times for 3+ digits to repeat within 100 digits, since the chances of that happening are less than 1/100.
I probably won't, but if I have more time for this, I'll try to do the next part.