#include <iostream>
#include <cstdlib> // rand and srand
#include <ctime>
using namespace std;

void rollDie(int sides, int numRolls){
	const int MIN_VALUE = 1;
	const int D4_MAX_VALUE = 4;
	const int D6_MAX_VALUE = 6;
	const int D8_MAX_VALUE = 8;
	const int D10_MAX_VALUE = 10;
	const int D12_MAX_VALUE = 12;
	const int D20_MAX_VALUE = 20;
	int count = 0;
	int die = 0;

	while(count < numRolls){
		if(sides == 4){
			// roll d4
			die = (rand() % (D4_MAX_VALUE - MIN_VALUE +1)) + MIN_VALUE;
			cout << "Roll " << count+1 << ": " << die << endl;
		}else if(sides == 6){
			// roll d6
			die = (rand() % (D6_MAX_VALUE - MIN_VALUE +1)) + MIN_VALUE;
			cout << "Roll " << count+1 << ": " << die << endl;
		}else if(sides == 8){
			// roll d8
			die = (rand() % (D8_MAX_VALUE - MIN_VALUE +1)) + MIN_VALUE;
			cout << "Roll " << count+1 << ": " << die << endl;
		}else if(sides == 10){
			// roll d10
			die = (rand() % (D10_MAX_VALUE - MIN_VALUE +1)) + MIN_VALUE;
			cout << "Roll " << count+1 << ": " << die << endl;
		}else if(sides == 12){
			// roll d12
			die = (rand() % (D12_MAX_VALUE - MIN_VALUE +1)) + MIN_VALUE;
			cout << "Roll " << count+1 << ": " << die << endl;
		}else if(sides == 20){
			// roll d20
			die = (rand() % (D20_MAX_VALUE - MIN_VALUE +1)) + MIN_VALUE;
			cout << "Roll " << count+1 << ": " << die << endl;
		}else{
			cout << "You didn't pick a valid number of sides, choose 4,6,8,10,12, or 20." << endl;
		}

		// never forget to increment the counter
		count++;
	}

	return;
}

// random number example
int main(){
	// only have to seed the rng once, so do that here:
	unsigned seed = time(0);
	srand(seed);


	unsigned numRolls;
	unsigned dieSides;
	char prompt;

	while(true){
		cout << "How many sides for the die? (choose 4,6,8,10,12,or 20): " << endl;
		cin >> dieSides;
		cout << "How many die rolls do you want? " << endl;
		cin >> numRolls;

		rollDie(dieSides, numRolls);
		cout << "Quit? (y/n): " << endl;
		cin >> prompt;
		if(prompt == 'y'){ break; }
	}

	return 0;
}