Guest User

Untitled

a guest
Jun 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // K = Pegs constraints: 3 <= K <= 5
  2. // N = Discs constraints: 1 <= N <= 8
  3.  
  4.  
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.  
  12. int i_pegs = 0; // count of Pegs
  13. int i_discs = 0; // count of Discs
  14.  
  15. while(i_pegs > 5 || i_pegs < 3)
  16. {
  17. cout << "Peg count: ";
  18. cin >> i_pegs; cout <<endl;
  19. }
  20.  
  21. while(i_discs > 8 || i_discs < 1)
  22. {
  23. cout << "Disc count: ";
  24. cin >> i_discs; cout <<endl;
  25. }
  26.  
  27. struct game // structure of the game
  28. {
  29. int peg1[8];
  30. int peg2[8];
  31. int peg3[8];
  32. int peg4[8];
  33. int peg5[8];
  34. };
  35.  
  36. game Pegs; // Declare Pegs as the Peg-game Structure.
  37. Pegs.peg1 = {0, 0, 0, 0, 0, 0, 0, 0};
  38.  
  39. Pegs.peg5 = Pegs.peg4 = Pegs.peg3 = Pegs.peg2 = Pegs.peg1;
  40.  
  41. int i = i_discs;
  42.  
  43. while(i >= 1) // Pegs.peg[0] is the bottom of the peg. Pegs.peg[7] is the top.
  44. {
  45. Pegs.peg1[i_discs - i] = i;
  46. i--;
  47. }
  48.  
  49.  
  50.  
  51.  
  52. system("pause");
  53.  
  54. return(0);
  55.  
  56. }
Add Comment
Please, Sign In to add comment