Ultima Dice 1.0

By N3M3S1S on Oct 05, 2010

Simple console dice roller made in C++

Works great, ready to compile and run.

// Ultima Dice 0.1 Beta
// xIRCxes++ Project by Neo Nemesis
// Dice Roller

#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;

int main ()
{
    srand(time(NULL));
    //cout << "Ultima Dice 0.1 Beta - xIRCxes++ Project by Neo Nemesis" <<endl;
    cout << "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»" <<endl;
    cout << "ºÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»º" <<endl;
    cout << "ºº                             Ultima Dice 1.0                             ºº" <<endl;
    cout << "ºº                             By: Neo Nemesis                             ºº" <<endl;
    cout << "ºº                             xIRCxes Project                             ºº" <<endl;
    cout << "ºº                                                                         ºº" <<endl;
    cout << "ºº                  Enter 1 for the main menu and press enter              ºº" <<endl;
    cout << "ºº                              Enter 0 to exit                            ºº" <<endl;
    cout << "ºº                                                                         ºº" <<endl;
    cout << "ºÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼº" <<endl;
    cout << "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ" <<endl;
    int a;
    cout << "Selection: ";
    cin >> a;
    if (a=1) {
       cout << "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»" <<endl;
       cout << "ºÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»º" <<endl;
       cout << "ºº                         Enter 1 to Roll Dice                            ºº" <<endl;
       cout << "ºº                            Enter 0 to exit                              ºº" <<endl;
       cout << "ºº                    Enter selection and press enter.                     ºº" <<endl;
       cout << "ºÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼº" <<endl;
       cout << "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ" <<endl;
       cout << "Selection: ";
       cin >> a;
       while (a!=0) {
          //Dice Roller
          int D, N;
          int result = 0;
          cout << "Enter the number of dice you wish to roll: ";
          cin >> N;
          cout << "Enter the size of the dice you wish to roll (i.e. the sides): ";
          cin >> D;
          // process
          for(int x=0;x<N;x++) {
             cout << "You rolled\t" << (D = rand()%20+1) << endl;
             result += D;
          }
          cout << "\nTotal = " << result << endl;
          cout << "Roll again?" <<endl;
          cout << "Enter 1 to roll again, 0 to exit." <<endl;
          cin >> a;
       }
   }
   return 0;
}

Comments

Sign in to comment.
sunslayer   -  Dec 29, 2010

while it's not necessary time.h is a C header file, ctime would be the C++ header

 Respond  
jaytea   -  Dec 29, 2010

i think you mean to use 'rand() % D + 1' and to assign that result to a different variable than D, since you need to retain user input.

 Respond  
N3M3S1S   -  Dec 29, 2010

Hmm I've never noticed, I'll have to look at that, and I'll let you know within the next day or so.

 Respond  
Back2Life   -  Dec 26, 2010

This script seems to work well, but I have on complaint. When it says enter the sides or whatever I enter 6, but when I roll all 6 of my dice it says I rolled one with 4, one with 20, one with 16, and more. Could you explain to me what the size means?

Not to get you wrong, this is a fantastic snippet.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.