Advertisement
Guest User

roll the dice

a guest
Apr 8th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int dice_sum, edge_sum;
  8.  
  9. class gameStart{
  10.     string s;
  11.     public:
  12.         void dice_roll(string &str)
  13.         {
  14.             for(int j=0; j<str.find("d"); ++j){
  15.                 s +=str[j];
  16.             }
  17.             dice_sum = stoi(s);
  18.             s.clear();
  19.             for(int k=str.find("d")+1; str[k]!=NULL; ++k){
  20.                 s +=str[k];
  21.             }
  22.             edge_sum = stoi(s);
  23.         }
  24. };
  25.  
  26. int main()
  27. {
  28.     //input
  29.     string str;
  30.     cout << "Roll the dice: ";
  31.     getline(cin, str);
  32.  
  33.     gameStart gs;
  34.     gs.dice_roll(str);
  35.  
  36.     //output
  37.     srand(time(0));
  38.     for (int i=0; i < dice_sum; ++i){
  39.     cout << 1 + rand() % edge_sum << endl;
  40.     }
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement