a mind reading game

ANY ONE PLEASE CHECKOUT IF THIS ONE WORKS WELL ,
OPEN FOR ANY SUGESTIONS !!!!!!!!!!!!!!!!!!!!!!!

This is an app ,just for fun , only thing you need to do is , choose a number and see what it
does!!!!!!!!!!!!!!!( inputs are necessary ) .
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
void main()
{ randomize();

int a[9][3],b[9][3],i,j,k,c[9][3],d[9][3];
cout<<"\t\t\t\tINSTRUCTIONS\n\t\t\t\t------------"<<endl<<"\n[1] You have to choose one number and remember it."<<endl<<"[2] Enter the COLUMN no when asked.\n[3] ENJOY!!!!!!!!\n\n";
cout<<"(1)	(2) 	(3)"<<endl;
for(i=0;i<9;i++)
{cout<<"\n";
 for(j=0;j<3;j++)
{ a[i][j]=random(99)+1;
 cout<<a[i][j]<<"\t";
 }
}
label:
int col;
cout<<"\n\nEnter column no:";
cin>>col;


if((col>3)||(col<1))
{
  cout<<"Sorry, incorrect input";
  goto label;
}


cout<<"\n\n................................................................\n";
cout<<"(1)	(2) 	(3)"<<endl;
//FIRST CHOISE TAKEN
if(col==1)
{
for(i=0,k=0;i<3;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][1];
	cout<<b[i][j]<<"\t";
  }
}

for(i=3,k=0;i<6;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][0];
	cout<<b[i][j]<<"\t";
  }
}

for(i=6,k=0;i<9;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][2];
	cout<<b[i][j]<<"\t";
  }
}
}

if(col==2)
{
for(i=0,k=0;i<3;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][0];
	cout<<b[i][j]<<"\t";
  }
}

for(i=3,k=0;i<6;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][1];
	cout<<b[i][j]<<"\t";
  }
}

for(i=6,k=0;i<9;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][2];
	cout<<b[i][j]<<"\t";
  }
}
}

if(col==3)
{
for(i=0,k=0;i<3;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][1];
	cout<<b[i][j]<<"\t";
  }
}

for(i=3,k=0;i<6;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][2];
	cout<<b[i][j]<<"\t";
  }
}

for(i=6,k=0;i<9;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {b[i][j]=a[k][0];
	cout<<b[i][j]<<"\t";
  }
}
}

//SECOND CHOISE TAKEN
label2:
cout<<"\n\nEnter column no:";
cin>>col;
if((col>3)||(col<1))
{
  cout<<"Sorry, incorrect input";
  goto label2;
}
cout<<"\n\n................................................................\n";
cout<<"(1)	(2) 	(3)"<<endl;
if(col==1)
{
for(i=0,k=0;i<3;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][1];
	cout<<c[i][j]<<"\t";
  }
}

for(i=3,k=0;i<6;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][0];
	cout<<c[i][j]<<"\t";
  }
}

for(i=6,k=0;i<9;k++,i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][2];
	cout<<c[i][j]<<"\t";
  }
}
}

if(col==2)
{
for(i=0,k=0;i<3;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][0];
	cout<<c[i][j]<<"\t";
  }
}

for(i=3,k=0;i<6;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][1];
	cout<<c[i][j]<<"\t";
  }
}

for(i=6,k=0;i<9;k++,i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][2];
	cout<<c[i][j]<<"\t";
  }
}
}

if(col==3)
{
for(i=0,k=0;i<3;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][1];
	cout<<c[i][j]<<"\t";
  }
}

for(i=3,k=0;i<6;i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][2];
	cout<<c[i][j]<<"\t";
  }
}

for(i=6,k=0;i<9;k++,i++)
{cout<<"\n";
 for(j=0;j<3;j++,k++)
  {c[i][j]=b[k][0];
	cout<<c[i][j]<<"\t";
  }
}
}



//THIRD CHOISE TAKEN
label3:
cout<<"\n\nEnter column no:";
cin>>col;
if((col>3)||(col<1))
{
  cout<<"Sorry, incorrect input";
  goto label3;
}
cout<<"\n\n................................................................\n";
if(col==1)
{
for(i=0,k=0;i<3;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][1];

  }
}

for(i=3,k=0;i<6;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][0];

  }
}

for(i=6,k=0;i<9;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][2];

  }
}
}

if(col==2)
{
for(i=0,k=0;i<3;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][0];

  }
}

for(i=3,k=0;i<6;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][1];

  }
}

for(i=6,k=0;i<9;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][2];

  }
}
}

if(col==3)
{
for(i=0,k=0;i<3;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][1];

  }
}

for(i=3,k=0;i<6;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][2];

  }
}

for(i=6,k=0;i<9;i++)
{
 for(j=0;j<3;j++,k++)
  {d[i][j]=c[k][0];

  }
}

}
cout<<"\n\n.................................................................\n";
cout<<"THE NUMBER CHOSEN IS  "<<d[4][1];
cout<<"\n.................................................................";

}
Randomize was not declared in this scope. (int main())
cout was not declared in this scope.
iostream.h is deprecated and doesn't exists anymore.
cin was not declared in this scope.
endl was not declared in this scope.
random was not declared in this scope.

I think something is not right.
Last edited on
Missing using namespace std;
identifier "randomize" is unidentified
identifier "random" is unidentified
@iQChange
He appears to be using Borland (or something similar). To fix, you can simply replace <iostream.h> with <iostream>, randomize with srand(time(NULL)), and random with the appropriate statements consisting of rand() and modifiers.
There should be system("pause"); at the end or something with similar function.
Not properly work. Some column has the same number. Or two columns have the same number.
Last edited on
closed account (j3Rz8vqX)
OPEN FOR ANY SUGESTIONS

Nice.

A possible suggestion, through example:
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
#include<iostream>
#include<cstdlib>           //Enable srand() and rand();
#include<ctime>             //Enable time() seed;
using std::cout;
using std::cin;
using std::endl;
void process(int first[9][3], int second[9][3],int min, int max, int index)
{
    for(int i=min,k=0;i<max;i++)
    {
        cout<<"\n";
        for(int j=0;j<3;j++,k++)
        {
            first[i][j]=second[k][index];
            cout<<first[i][j]<<"\t";
        }
    }
}
int main()
{
    srand(time(0));

    int a[9][3],b[9][3],c[9][3],d[9][3];
    cout<<"\t\t\t\tINSTRUCTIONS\n\t\t\t\t------------"<<endl<<
          "\n[1] You have to choose one number and remember it."<<endl<<
          "[2] Enter the COLUMN no when asked.\n[3] ENJOY!!!!!!!!\n\n";
    cout<<"(1)	(2) 	(3)"<<endl;
    for(int i=0;i<9;i++)
    {
        cout<<"\n";
        for(int j=0;j<3;j++)
        {
            a[i][j]=rand()%99+1;
            cout<<a[i][j]<<"\t";
        }
    }
    int col;
    const int minMax[4]={0,3,6,9};                      //Encapsulated your alternating min and max into an array.
    const int index[3][3]={{1,0,2},{0,1,2},{1,2,0}};    //Encapsulated your alternating cols into an array.
    int (*arrys[4])[3] = {a,b,c,d};                     //Encapsulated your alternating arrays into an array.

    for(int i=0;i<3;i++)                                //The three choices taken:
    {
        do
        {
            cout<<"\n\nEnter column no: ";
            cin>>col;

            if((col>3)||(col<1))
                cout<<"Sorry, incorrect input";
            else
                break;                                  //Leaves while-loop, if correct data was entered.
        }while(true);                                   //A never ending while loop, something inside is expected to break it.

        cout<<"\n\n................................................................\n";
        cout<<"(1)	(2) 	(3)"<<endl;
        for(int j=0;j<3;j++)                            //The three cols checked.
        {
            process(arrys[i+1],arrys[i],minMax[j],minMax[j+1],index[col-1][j]);     //Example: process(b,a,0,3,1);
        }
    }
    cout<<"\n\n.................................................................\n";
    cout<<"THE NUMBER CHOSEN IS  "<<d[4][1];
    cout<<"\n.................................................................";
    cout<<"\nPress enter to quit: ";
    cin.get();//Pause, for command line execution.
    return 0;
}

Your code with slight condensing.

Good Job!

Edit: added a bit of comments to clarify.
Last edited on


dleanjeanz wrote:
Missing using namespace std;


That's actually a bad idea.

Same with this:
system("pause");

There has been lots written as to why this is so. Search this forum or the web to see.

Regards

I know system("pause") is somewhat evil. I've found that cin.get(), getch(), _getch() doesn't work every time. So I think using system("pause") just once doesn't hurt anyone.
well i m using borland and really it works on my compiler

i dont really know much about key words like system("pause")
may b coz im not pro yet just started it
closed account (j3Rz8vqX)
system()
Makes calls to your system(command line) to do something. In this case, it would call the pause command; you can test this by going to your command prompt, console, or terminal and enter: pause.

Normally, antivirus programs tend to flag these commands as a virus because it enables, small programs, the scope of the terminal or console; also, "pause" could be infected - though not likely.

In most cases, the below code will be more than enough to suffice for a pause; without calling the console:
1
2
3
4
    cout<<"\nPaused: Press enter: ";
    cin.clear();
    cin.ignore(255,'\n');
    cin.get();
Paused: Press enter:
hey iv e been wondering which compiler do u guys use
the code (the "suggestion") is not working in my compiler

THE NEW C++ 11 N IS NOT WORKING IN BORLAND 4.5

TO
Dput

I personally use Visual Studio 2013 Ultimate, other common ones people use on here are Code Blocks and Eclipse.

I would use Visual Studio or Eclipse for the simple reason that those two are more widely used in software development houses and being comfortable using them would be an advantage.

You can get a free copy of Visual Studio Express from: http://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx

Eclipse: http://www.eclipse.org/downloads/

There are other decent IDE's out there, but for the reasons I explained above you are better off sticking with the more common ones.



closed account (j3Rz8vqX)
@nanduknight10

Your cin.get() may require arguments:
http://www.minich.com/education/wyo/cplusplus/cplusplusch10/getfunction.htm
Example:
1
2
3
4
5
6
7
8
9
#include <iostream.h>

void main()
{
   char line[25];
   cout << " Type a line terminated by carriage return\n>";
   cin.get( line, 25 );
   cout << ' ' << line;
}


This is because Borland 4.5 doesnt work with <iostream> and requires <iostream.h>

iostream to iostream.h:
http://members.gamedev.net/sicrane/articles/iostream.html

I am uncertain about Borland 5.5, I've heard that there is support for <iostream>
Last edited on
its 4.5
that might b the reason
Topic archived. No new replies allowed.