Advertisement
shadowlucario50

C++ DND Die

Apr 26th, 2025
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | Source Code | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.     //Challenge: Create a program to roll any amount of dice with any amount of sides. 3d6 stuff.
  5.  
  6.     srand(time(NULL));
  7.  
  8.     int sides;
  9.     int amount;
  10.     int roll;
  11.     int total = 0;
  12.     char yn;
  13.  
  14.     do{
  15.         std::cout << "**DND Dice**\n";
  16.         std::cout << "Please input the number of sides. ";
  17.         std::cin >> sides;
  18.  
  19.         std::cout << "Input the amount of dice to roll. ";
  20.         std::cin >> amount;
  21.  
  22.         std::cout << "You are rolling " << amount << "d" << sides << ". Is this correct? Y/N ";
  23.         std::cin >> yn;
  24.  
  25.         if(yn == 'Y') {yn = 'y';}
  26.     }while(yn != 'y');
  27.  
  28.     for(int i = 0; i < amount; i++)  {
  29.         roll = rand() % sides + 1;
  30.         std::cout << roll << '\n';
  31.         total += roll;
  32.     }
  33.  
  34.     std::cout << "Total: " << total;
  35.  
  36.     return 0;
  37. }
Tags: C++ Code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement