Dice Gen 0.1

Published January 25, 2011
Advertisement
// I wrote this little program and decided to put it here to remind myself what I covered in programming so far and to
// share as well.

#include
#include
#include

// DiceGen 0.1 by: Michael T. Dixon (6-7-2010)

using namespace std;


int die;

int dieChoice;
int dieTotal;

int Hold_die1;
int Hold_die2;
int Hold_die3;

bool quit = false;

void greet();

void roll_d4();
void roll_d6();
void roll_d8();
void roll_d12();

int randomNumber = rand();

int main(int argc, char *argv[])
{

do
{

srand(time(0));

greet();

while(!(cin >> dieChoice)){

system("CLS");
cin.clear();
cin.ignore(100, '\n');

greet();

cout << "\n\n\tPlease choose a number 1-5\n";
cout << "\n\t?:";
}

switch(dieChoice){
case 1:

roll_d4();
break;

case 2:

roll_d6();
break;

case 3:

roll_d8();
break;

case 4:

roll_d12();
break;

case 5:
cout << "\n\n\tThanks for Playing\n\n";
quit = true;
break;

default:
cout << "\tTry again\n\n";
}
cout << "\n\n\t";
system("PAUSE");
system("CLS");

}while(!quit);

return EXIT_SUCCESS;
}

void greet()
{
cout << "\n\n\t--[Welcome to the D&D DiceGen 0.1]--\n\n";
cout << "\tPlease choose 1-4 to roll a die three times.\n\n";

cout << "\t----MENU CHOICE----\n\n";
cout << "\t1 - d4 (4 sided die)\n";
cout << "\t2 - d6 (6 sided die)\n";
cout << "\t3 - d8 (8 sided die)\n";
cout << "\t4 - d12 (12 sided die)\n";
cout << "\t5 - Quit\n";
cout << "\n\t?:";
}


void roll_d4()
{
cout << "\n\td4: You rolled: ";
for (int i = 1; i <= 3; randomNumber = rand())
{

die = (randomNumber %4) + 1;

cout << die << " ";

if (i==1){Hold_die1=die;}
if (i==2){Hold_die2=die;}
if (i==3){Hold_die3=die;}

i++;
}
dieTotal=Hold_die1+Hold_die2+Hold_die3;

cout << "\n\n\tYour total: " << dieTotal;
}


void roll_d6()
{

cout << "\n\td6: You rolled: ";
for (int i = 1; i <= 3; randomNumber = rand())
{

die = (randomNumber %6) + 1;
cout << die << " ";

if (i==1){Hold_die1=die;}
if (i==2){Hold_die2=die;}
if (i==3){Hold_die3=die;}

i++;
}
dieTotal=Hold_die1+Hold_die2+Hold_die3;

cout << "\n\n\tYour total: " << dieTotal;
}


void roll_d8()
{

cout << "\n\td8: You rolled: ";


for (int i = 1; i <= 3; randomNumber = rand())
{

die = (randomNumber %8) + 1;
cout << die << " ";

if (i==1){Hold_die1=die;}
if (i==2){Hold_die2=die;}
if (i==3){Hold_die3=die;}

i++;

}
dieTotal=Hold_die1+Hold_die2+Hold_die3;

cout << "\n\n\tYour total: " << dieTotal;
}

void roll_d12()
{
cout << "\n\td12: You rolled: ";
for (int i = 1; i <= 3; randomNumber = rand())
{

die = (randomNumber %12) + 1;
cout << die << " ";

if (i==1){Hold_die1=die;}
if (i==2){Hold_die2=die;}
if (i==3){Hold_die3=die;}

i++;
}
dieTotal=Hold_die1+Hold_die2+Hold_die3;

cout << "\n\n\tYour total: " << dieTotal;

}


0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Dice Gen 0.1

900 views
Advertisement