I want to print the first number that first counts to 4, for example, I have this random function, I want to see the first number that reaches 4 times. so it's the first number that prints himself 4 times. For example:
int n;
int count1 = 0;
int count2 = 0;
int count3 = 0;
while (true) {
cout << "Enter a number btween 1-3" << endl;
cin >> n;
if (n == 1) {
count1++;
}
if (n == 2) {
count2++;
}
if (n == 3) {
count3++;
}
if (count1 == 4) {
cout << "You printed the number 1 4 times!";
break;
}
if (count2 == 4) {
cout << "You printed the number 2 4 times!";
break;
}
if (count3 == 4) {
cout << "You printed the number 3 4 times!";
break;
}
But what would I do if it was 1-1000 numbers not just 1-3 what would I do then?
I want to do that but on a random function - the first number that the count of that number is 4 times print the number -
int fun() {
srand(time(NULL));
return rand() % 3;
}
Then I want to do in main that first number that reaches for example 4 times print this number.
I tried doing something like this:
for (int i = 0; i < 31; i++) {
arr[fun()]++;
cout << arr[fun()];
if (arr[fun()] == 4) {
cout << arr[fun()];
}
}