All pastes #719480 Raw Edit

Text-based dices

public cpp v1 · immutable
#719480 ·published 2007-09-29 10:27 UTC
rendered paste body
#include <iostream>#include <iomanip>#include <stdlib.h>#include <time.h>#include <string>using namespace std;int main(){	int 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 << "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;		}		cout << "You rolled: " << rand() % die + 1;		cout << endl << endl;	}	return 0;}