Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // K = Pegs constraints: 3 <= K <= 5
- // N = Discs constraints: 1 <= N <= 8
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int i_pegs = 0; // count of Pegs
- int i_discs = 0; // count of Discs
- while(i_pegs > 5 || i_pegs < 3)
- {
- cout << "Peg count: ";
- cin >> i_pegs; cout <<endl;
- }
- while(i_discs > 8 || i_discs < 1)
- {
- cout << "Disc count: ";
- cin >> i_discs; cout <<endl;
- }
- struct game // structure of the game
- {
- int peg1[8];
- int peg2[8];
- int peg3[8];
- int peg4[8];
- int peg5[8];
- };
- game Pegs; // Declare Pegs as the Peg-game Structure.
- Pegs.peg1 = {0, 0, 0, 0, 0, 0, 0, 0};
- Pegs.peg5 = Pegs.peg4 = Pegs.peg3 = Pegs.peg2 = Pegs.peg1;
- int i = i_discs;
- while(i >= 1) // Pegs.peg[0] is the bottom of the peg. Pegs.peg[7] is the top.
- {
- Pegs.peg1[i_discs - i] = i;
- i--;
- }
- system("pause");
- return(0);
- }
Add Comment
Please, Sign In to add comment