#include #include #include #include #include using namespace std; int main() { int x, die; string roll, tmp; srand(time(0)); while(true) { cout << "What die do you want to use (6, 20 or 100)? "; cin >> die; if (cin.fail() || (die != 6 && die != 20 && die != 100)) { cin.clear(); getline(cin, tmp); cout << "Invalid die type, please try again." << endl << endl; continue; } cout << endl; cout << "How many dices do you want to roll? "; cin >> x; cout << endl; cout << "Type 'roll' to roll the die: "; cin >> roll; if (cin.fail() || roll != "roll") { cin.clear(); getline(cin, tmp); cout << "Invalid command, please try again." << endl << endl; continue; } if(x>=2) { cout << "You rolled: " << x << "d" << die << "= " << rand() % die + 1 * x; cout << endl << endl; } if (x<=1) { cout << "You rolled: " << rand() % die + 1; cout << endl << endl; } } return 0; }