Playing NIM with modified conditions

My project was to make the game of NIM with some modified conditions. So far, I've been able to satisfy those, such as adding "sports commentary" and changing the amount of objects that players can remove to 4. I also made it so that the computer doesn't lose on accident due to rand() statements. The one that I'm struggling with is setting it up so that the program prints out symbols for how many objects are left.

It should be something like this.

num_objects = 4 cout << "****\n";

However, I'm struggling to figure out how to get it to print a different amount for however many numbers are left. I'm guessing it has something to do with a "for loop," but I don't know exactly what. Here is my code so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  /* The game of NIM */
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{

		cout << "Welcome to the game of NIM!\n";
		cout << "---------------------------\n";
		cout << "You will take turns against a computer,\nremoving anywhere from 1-3 objects from the game.\n";
		cout << "Whoever ends up removing the last object from the game loses,\nand the other player wins!\n\n";

	int num_objects = 23;
	int current_player = 1;
	int move;
	int minimum_move = 1;
	int maximum_move = 4;
	

	do
	{
		if (current_player == 1)
		{
			cout << "Player 1, enter your move (1-4): ";
			cin >> move;
			while (move < minimum_move || move > maximum_move || move > num_objects)
			{
				cout << "Illegal move. \nEnter a new move: ";
				cin >> move;
			}
		}
		
		else
		{

			switch (num_objects)
			{
			case 1: move = 1;
				break;
			case 2: move = 1;
				break;
			case 3: move = 2;
				break;
			case 4: move = 3;
				break;
			case 5: move = 4;
				break;
			default: move = 1 + rand() % 4;
				break;
			}

			/*do
			{
				move = 1 + rand() % 3;
			}
			*/
			while (move < minimum_move || move > maximum_move || move > num_objects);
			cout << "Computer removed " << move << endl;
		}

		num_objects = num_objects - move;
		cout << num_objects << " objects remaining.\n";

		if (num_objects > 15 && num_objects < 19)
		{
			cout << "Things are getting pretty intense in here!\n";
		}

		if (num_objects < 7 && num_objects > 3)
		{
			cout << "This is a close game!\n";
		}

		current_player = (current_player + 1) % 2;
	}

	while (num_objects > 0);


	if (current_player == 1)
	{
		cout << "Player 1 wins! Good job! :D\n";
	}
	
	else
	{
		cout << "The computer wins! Good try!\n";
	}

	cin.ignore();
	cout << "\nPress enter to quit.\n";
	cin.ignore();
	return 0;
}
Topic archived. No new replies allowed.