fork download
  1. #include <cstdlib>
  2. #include <ctime>
  3. #include <iostream>
  4.  
  5. struct Dices
  6. {
  7. int one; // Dice One
  8. int two; // Dice Two
  9. };
  10.  
  11. Dices roll_dices()
  12. {
  13. Dices d;
  14.  
  15. d.one = std::rand() % 6 + 1;
  16. d.two = std::rand() % 6 + 1;
  17. return d;
  18. }
  19.  
  20. bool check_double(Dices d)
  21. {
  22. if (d.one == d.two)
  23. return true;
  24.  
  25. return false;
  26. }
  27.  
  28. int main()
  29. {
  30. std::srand(std::time(NULL));
  31.  
  32. Dices d = roll_dices();
  33.  
  34. std::cout << "You rolled: " << d.one << " and " << d.two << "!\n";
  35.  
  36. if (check_double(d))
  37. std::cout << "You rolled a double!\n";
  38. }
  39.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
You rolled: 4 and 5!