help me solve it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

bool check (int z[],int y,bool exist=false) {
int x=0;
while (x<6) {
if ( z[x]==y ) {
exist=true;}
else {
x++;}
}
return check; }
int main()
{
int a[]={1, 2, 3, 4, 5};
int y;
bool h=false;
cout << "enter a number: ";
cin >> y;
check ( a,y,h);
do{
cout << "else:" << endl;
cin >> y;  }while (h=false);
return 0;}


I want to still asking to put a number untill it is one of these (1,2,3,4,5)
Change it to:
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
#include <iostream>
using namespace std;

bool check (int z[],int y,bool exist=false) {
bool exist=false;
int x=0;
while (x<6) {
if ( z[x]==y ) {
exist=true;}
else {
x++;}
return exist;
}
return check; }
int main()
{
int a[]={1, 2, 3, 4, 5};
int y;
bool h=false;
cout << "enter a number: ";
cin >> y;
check ( a,y,h);
while (check ( a,y)==false)do{
cout << "else:" << endl;
cin >> y;  }while (h=false);
return 0;}
ok ,now i'm trying to use a similar function for a tic tac toe game. Help:
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
#include <iostream>
using namespace std;

bool check (int z[],int y) {
bool exist=false;
int x=0;
for (int d;d<sizeof (z);d++) {
if ( z[x]==y ) {
	exist=true;}}
return exist;
}
int main()
{
int a[4];
int b[4];
char p1[100];
char p2[100];
cout << "Welcome to tic tac toe"<<endl;
cout << "1|2|3" << endl;
cout << "4|5|6" << endl;
cout << "7|8|9" << endl;
cout << "p1 enter your name: ";
cin >> p1;
cout << "p2: ";
cin >> p2;
for (int x=0;x<6;x++) {
cout << p1 << "choose a case: ";
cin >> a[x];
cout << "you entered: " << a[x] << endl;
if ((check(a, 1)==true)&&( check (a, 2)==true) && (check (a, 3)==true)){ break;}//i want to say that if p1 choosed case 1,2 and 3 he won 
//i didnt continue cause it sill not working.
}
return 0;}
help!
On line 7: sizeof (z) is the size of the pointer to that array, it doesn't say how many fields z has. Pass the number of fields as an extra parameter.

On line 8: x is not changed. Use d instead
Topic archived. No new replies allowed.