#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(nullptr)); int num_dice, num_sides; cout << "how many dice?:" << endl; cin >> num_dice; cout << "how many sides?" << endl; cin >> num_sides; cout << "rolls:" << endl; int first_roll = 0; // Initialize yahtzee to true. Note the value of the first roll, // and if the current roll is not equal to the first roll, it is // not a yahtzee. bool yahtzee = true; for (int i = 0; i < num_dice; ++i) { int roll = rand() % num_sides + 1; cout << roll << " "; if (i == 0) { first_roll = roll; } else if (roll != first_roll) { yahtzee = false; } } cout << endl; if (yahtzee) { cout << "Yahtzee!" << endl; } return 0; }
7
5/9/2024, 11:52:27 PM