Sample run
Let’s roll some dice!
You rolled a 3
You rolled a 5
You rolled a 4
You rolled a 1
You rolled a 6
You rolled a 1
You rolled a 4
You rolled a 2
You rolled a 3
You rolled a 5
Three in a row in 10 rolls.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main() {
int n_rolls = 0;
int n_odd = 0;
int dice;
srand(time(0));
cout << "Let's roll some dice!" << endl;
while (true) {
dice = rand() % 6 + 1;
cout << "You rolled a " << dice << endl;
n_rolls++;
if (dice %2) {
if (++n_odd == 3) {
break;
}
}
else {
n_odd = 0;
}
}
cout << "Three in a row in " << n_rolls << " rols." << endl;
}
Fix
Comments
Leave a comment