dice.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <string>
  2. #include <vector>
  3. class Dice {
  4. public:
  5. int white1, white2, red, yellow, green, blue;
  6. int roll();
  7. void print();
  8. };
  9. int Dice::roll() {
  10. std::vector<int> output;
  11. // generate 6 random numbers to assign to each die
  12. for (int i = 0; i<6; i++) {
  13. // store numbers generated from rand into output
  14. output.push_back((rand() % 6) + 1);
  15. }
  16. white1 = output[0];
  17. white2 = output[1];
  18. red = output[2];
  19. yellow = output[3];
  20. green = output[4];
  21. blue = output[5];
  22. return 15;
  23. }
  24. void Dice::print() {
  25. fprintf (stdout, "White1 Dice: %d\n", white1);
  26. fprintf (stdout, "White2 Dice: %d\n", white2);
  27. fprintf (stdout, "Yellow Dice: %d\n", yellow);
  28. fprintf (stdout, "Red Dice: %d\n", red);
  29. fprintf (stdout, "Blue Dice: %d\n", blue);
  30. fprintf (stdout, "Green Dice: %d\n", green);
  31. }
  32. /* Dice humphe;
  33. humphe = new Dice();
  34. humphe.rollDice();
  35. fprintf(stdout, "the red die %d\n", humphe.red);
  36. struct SDie {
  37. int number;
  38. std::string color;
  39. };
  40. class CDie {
  41. int number; std::string color;
  42. int roll();
  43. };
  44. SDie greebDie = {1, "brellow"};
  45. CDie yellowDie;
  46. yellowDie = newC Die();
  47. yellowDie.number = 1;
  48. yellowDie.color = "preple";
  49. yellowDie.roll(); */