MasterMind

Hello people, it has been a while since i posted but i guess this would be a good time to post.

I was bored so i decided to program MasterMind, it's fairly simple to program and, for the sake of "free software" i'll leave the source code here. Any suggestions and tips would be helpful.(I did not use functions because i wrote the game twice and it didnt work the first time so i just put it all inside main).
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
95
96
97
98
99
100
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){

	char colors[4];

	srand(time(0));
	int randomint = (rand()%5)+1;

	for(int i=0;i<4;i++){
	randomint = (rand()%5)+1;

	 switch(randomint){
	 case 1:
		 colors[i] = 'R';
		 break;
	 case 2:
		 colors[i] = 'B';
		 break;
	 case 3:
		 colors[i] = 'Y';
		 break;
	 case 4:
		 colors[i] = 'P';
		 break;
	 case 5:
		 colors[i] = 'G';
		 break;
	 
	 }
	}

	char usercolors[4];

	cout << "We have our colors!" << endl;
	cout << endl << endl;
	int turncounter = 0;
	while(turncounter != 12){
		turncounter++;

		cout << "Current try: " << turncounter << endl;

		for(int i=0;i<4;i++){
			cout << "Color " << i << ": "; 
			cin >> usercolors[i];
			cout << endl;
		}

		for(int i=0;i<4;i++){		
			if(usercolors[i] == colors[i])
				cout << "R" << " ";
		}

		if(usercolors[0] == colors[1] || 
		   usercolors[0] == colors[2] ||
		   usercolors[0] == colors[3] ){
			   cout << "W" << " ";
		}
		   if(usercolors[1] == colors[0] ||
			  usercolors[1] == colors[2] ||
		       usercolors[1] == colors[3]){
				   cout << "W" << " ";
		   }
		   if(usercolors[2] == colors[0] ||
		   usercolors[2] == colors[1] ||
		   usercolors[2] == colors[3]){
			   cout << "W" << " ";
		   }
		   if(usercolors[3] == colors[0] ||
		   usercolors[3] == colors[1] ||
		   usercolors[3] == colors[2])
			{
				cout << "W" << " ";
			}

		cout << endl << endl;

		if(usercolors[0] == colors[0] &&
		   usercolors[1] == colors[1] &&
		   usercolors[2] == colors[2] &&
		   usercolors[3] == colors[3])
		{
			cout << "You win! Number of tries: " << turncounter << endl;
			turncounter = 12;
		}else{
			cout << "Nope." << endl << endl;
		}

	}
	if(turncounter == 12){
		cout << "You lost." << endl;
	}

	cin.get();
	cin.get();
	return 0;
}
Just FYI, it isn't Free Software unless the code is offered under a license that allows the code to be modified and redistributed. The most common Free Software license is the GNU GPL (http://www.gnu.org/licenses/gpl.html).

However, the usual practice for small works like yours is to place it in the public domain.
Oh ok, my bad then :p But yeah feel free to use it modify it, do whatever you want with it :) In the meanwhile i'll code a better version of this.
Topic archived. No new replies allowed.