if statement always false[not solved yet]

firstly sorry for my bad english
secondly i am still learning about c++ and i am trying to make a ticktacktoe game. I made a simple one with no ai but i decide to add an option to play against computer. And i code like that(i know this is really bad):


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
/*
  Name: TickTackToeFinal
  Copyright: 
  Author: 
  Date: 26.06.13 20:41
  Description: 
*/



#include <iostream>
#include <string>

using namespace std;

    char a=49;
    char b=50;
    char c=51;
    char d=52;
    char e=53;
    char f=54;
    char g=55;
    char h=56;
    char i=57; 

int sinir, oyun=1;

int bilgisayarimkansiz (int ust,int alt,int birinci,int tur){
    if((g==88&&d==88&&a!=79)||(i==88&&e==88&&a!=79)){return 1;}
    if((a==88&&c==88&&b!=79)||(h==88&&e==88&&b!=79)){return 2;}
    if((a==88&&b==88&&c!=79)||(b==88&&c==88&&c!=79)||(f==88&&i==88&&c!=79)){return 3;}
    if((a==88&&g==88&&d!=79)||(f==88&&e==88&&d!=79)){return 4;}
    if((a==88&&i==88&&e!=79)||(b==88&&h==88&&e!=79)||(c==88&&g==88&&e!=79)||(d==88&&f==88&&e!=79)){return 5;}
    if((c==88&&i==88&&f!=79)||(d==88&&e==88&&f!=79)){return 6;}
    if((a==88&&d==88&&f!=79)||(c==88&&e==88&&g!=79)){return 7;}
    if((g==88&&i==88&&h!=79)||(b==88&&e==88&&g!=79)){return 8;
    if((a==88&&e==88&&i!=79)||(c==88&&f==88&&i!=79)||(g==88&&h==88&&i!=79)){return 9;}
    }   
    if(tur==2) {while(1){
    int sonuc=rand()%(ust-alt)+alt;
    if(birinci==1&&sonuc!=6&&sonuc!=8){return sonuc;} 
    if(birinci==2&&sonuc!=4&&sonuc!=6&&sonuc!=7&&sonuc!=9){return sonuc;} 
    if(birinci==3&&sonuc!=4&&sonuc!=8){return sonuc;} 
    if(birinci==4&&sonuc!=2&&sonuc!=3&&sonuc!=8&&sonuc!=9){return sonuc;} 
    if(birinci==5){return sonuc;} 
    if(birinci==6&&sonuc!=1&&sonuc!=2&&sonuc!=7&&sonuc!=8){return sonuc;} 
    if(birinci==7&&sonuc!=2&&sonuc!=6){return sonuc;} 
    if(birinci==8&&sonuc!=1&&sonuc!=3&&sonuc!=4&&sonuc!=6){return sonuc;} 
    if(birinci==9&&sonuc!=2&&sonuc!=4){return sonuc;}    
}
    }
}
    
    int bilgisayarzor (int ust,int alt,int birinci){
    if(a==88&&b==88&&c!=79){return 3;}
    if(a==88&&d==88&&f!=79){return 7;}
    if(a==88&&e==88&&i!=79){return 9;}
    if(b==88&&c==88&&c!=79){return 3;}
    if(b==88&&e==88&&g!=79){return 8;}
    if(c==88&&f==88&&i!=79){return 9;}
    if(c==88&&e==88&&g!=79){return 7;}
    if(d==88&&e==88&&f!=79){return 6;}
    if(f==88&&i==88&&c!=79){return 3;}
    if(f==88&&e==88&&d!=79){return 4;}
    if(g==88&&h==88&&i!=79){return 9;}
    if(g==88&&d==88&&a!=79){return 1;}
    if(h==88&&e==88&&b!=79){return 2;}
    if(i==88&&e==88&&a!=79){return 1;} 
    
    while(1){int sonuc=rand()%(ust-alt)+alt;
       
    if(birinci==1&&sonuc!=6&&sonuc!=8){return sonuc;} 
    if(birinci==2&&sonuc!=4&&sonuc!=6&&sonuc!=7&&sonuc!=9){return sonuc;} 
    if(birinci==3&&sonuc!=4&&sonuc!=8){return sonuc;} 
    if(birinci==4&&sonuc!=2&&sonuc!=3&&sonuc!=8&&sonuc!=9){return sonuc;} 
    if(birinci==5){return sonuc;} 
    if(birinci==6&&sonuc!=1&&sonuc!=2&&sonuc!=7&&sonuc!=8){return sonuc;} 
    if(birinci==7&&sonuc!=2&&sonuc!=6){return sonuc;} 
    if(birinci==8&&sonuc!=1&&sonuc!=3&&sonuc!=4&&sonuc!=6){return sonuc;} 
    if(birinci==9&&sonuc!=2&&sonuc!=4){return sonuc;}    
    
}
    }
    
int bilgisayarorta (int ust,int alt,int birinci){
    while(1){int sonuc=rand()%(ust-alt)+alt;
    if(birinci==1&&sonuc!=6&&sonuc!=8){return sonuc;} 
    if(birinci==2&&sonuc!=4&&sonuc!=6&&sonuc!=7&&sonuc!=9){return sonuc;} 
    if(birinci==3&&sonuc!=4&&sonuc!=8){return sonuc;} 
    if(birinci==4&&sonuc!=2&&sonuc!=3&&sonuc!=8&&sonuc!=9){return sonuc;} 
    if(birinci==5){return sonuc;} 
    if(birinci==6&&sonuc!=1&&sonuc!=2&&sonuc!=7&&sonuc!=8){return sonuc;} 
    if(birinci==7&&sonuc!=2&&sonuc!=6){return sonuc;} 
    if(birinci==8&&sonuc!=1&&sonuc!=3&&sonuc!=4&&sonuc!=6){return sonuc;} 
    if(birinci==9&&sonuc!=2&&sonuc!=4){return sonuc;}    
    
}
    }

int bilgisayarkolay (int ust,int alt){
    return rand()%(ust-alt)+alt;
    
    
    }


when i run the game its always play randomly(last if statements in bilgisayar functions.


not:bilgisayar means computer
zor means hard
orta means medium
kolay means easy
oyuncu means player
tur means round
oyun means game
Last edited on
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
int ticktacktoe(char a, char b, char c, char d, char e, char f, char g, char h, char i, string oyuncu, int tur)
{    int x;
     if(sinir<10){
     cout<<"|------TickTackToe------|"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-----------| "<<a<<" | "<<b<<" | "<<c<<" |"<<endl;
     cout<<"|-OYUN------|---|---|---|"<<endl;
     cout<<"|-"<<oyun<<"/"<<sinir<<"-------| "<<d<<" | "<<e<<" | "<<f<<" |"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-"<<tur<<".TUR-----| "<<g<<" | "<<h<<" | "<<i<<" |"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-----------------------|"<<endl;
     cout<<oyuncu<<"'nin sirasi:";}
     if(sinir>=10){
     cout<<"|------TickTackToe------|"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-----------| "<<a<<" | "<<b<<" | "<<c<<" |"<<endl;
     cout<<"|-OYUN------|---|---|---|"<<endl;
     cout<<"|-"<<oyun<<"/"<<sinir<<"------| "<<d<<" | "<<e<<" | "<<f<<" |"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-"<<tur<<".TUR-----| "<<g<<" | "<<h<<" | "<<i<<" |"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-----------------------|"<<endl;
     cout<<oyuncu<<"'nin sirasi:";}
     if(oyun>=10){
     cout<<"|------TickTackToe------|"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-----------| "<<a<<" | "<<b<<" | "<<c<<" |"<<endl;
     cout<<"|-OYUN------|---|---|---|"<<endl;
     cout<<"|-"<<oyun<<"/"<<sinir<<"------| "<<d<<" | "<<e<<" | "<<f<<" |"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-"<<tur<<".TUR-----| "<<g<<" | "<<h<<" | "<<i<<" |"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-----------------------|"<<endl;
     cout<<oyuncu<<"'nin sirasi:";}
     if(oyun>=10&&sinir>=10){
     cout<<"|------TickTackToe------|"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-----------| "<<a<<" | "<<b<<" | "<<c<<" |"<<endl;
     cout<<"|-OYUN------|---|---|---|"<<endl;
     cout<<"|-"<<oyun<<"/"<<sinir<<"-----| "<<d<<" | "<<e<<" | "<<f<<" |"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-"<<tur<<".TUR-----| "<<g<<" | "<<h<<" | "<<i<<" |"<<endl;
     cout<<"|-----------|---|---|---|"<<endl;
     cout<<"|-----------------------|"<<endl;
     cout<<oyuncu<<"'nin sirasi:";}
     
     cin>>x;
     cout<<"\n\n";
     return x;
     
     }


int main(){
    int puan1=0, puan2=0 , birinci, ikinci, kisi, zorluk;
    
    do {
    cout<<"1.Tek Oyuncu\n2.Iki Oyuncu";
    cin>>kisi;
         
             } while(kisi!=1&&kisi!=2);
    
    string oyuncu1, oyuncu2;
    if(kisi==2)
    {cout<<"1.oyuncunun adini giriniz:";
    cin>>oyuncu1;
    cout<<"2.oyuncunun adini giriniz:";
    cin>>oyuncu2;
    cout<<"Oynamak istediginiz oyun sayisini girin:";
    cin >>sinir;}
    
    if(kisi==1)
    {
    do {cout<<"Zorlugu secin:";
    cout<<"\n1.Cok Kolay\n2.Kolay\n3.Normal\n4.Zor";
    cin>>zorluk;} while(zorluk!=1&&zorluk!=2&&zorluk!=3&&zorluk!=4);   
    cout<<"Adini giriniz:";
    cin>>oyuncu1;
    oyuncu2="Bilgisayar";
    cout<<"Oynamak istediginiz oyun sayisini girin:";
    cin >>sinir;}
    
    while (oyun<=sinir){
    char a=49;
    char b=50;
    char c=51;
    char d=52;
    char e=53;
    char f=54;
    char g=55;
    char h=56;
    char i=57; 
    if(oyun==1) {cout<<"TickTackToe'ye baslamak icin bir tusa basin.\n";}
    else  {cout<<oyun<<". oyuna baslamak icin bir tusa basin";}
    cin.ignore();
    cin.get();
    for(int tur=1; tur<10; ++tur){
    
  while(1){
   birinci=ticktacktoe(a,b,c,d,e,f,g,h,i,oyuncu1,tur);
   if(birinci==1&&a!=79&&a!=88) {a=88;++tur;break;}
   else if(birinci==2&&b!=79&&b!=88) {b=88;++tur;break;}
   else if(birinci==3&&c!=79&&c!=88) {c=88;++tur;break;}
   else if(birinci==4&&d!=79&&d!=88) {d=88;++tur;break;}
   else if(birinci==5&&e!=79&&e!=88) {e=88;++tur;break;}
   else if(birinci==6&&f!=79&&f!=88) {f=88;++tur;break;}
   else if(birinci==7&&g!=79&&g!=88) {g=88;++tur;break;}
   else if(birinci==8&&h!=79&&h!=88) {h=88;++tur;break;}
   else if(birinci==9&&i!=79&&i!=88) {i=88;++tur;break;}                        
   else {cout<<"Hatali giris yaptiniz.\n";continue;}                 
   }                                      
                                          
    if(a==88&&b==88&&c==88) {++puan1;break;} 
    else if(d==88&&e==88&&f==88) {++puan1;break;} 
    else if(g==88&&h==88&&i==88) {++puan1;break;}
    else if(a==88&&d==88&&g==88) {++puan1;break;}
    else if(b==88&&e==88&&h==88) {++puan1;break;}
    else if(c==88&&f==88&&i==88) {++puan1;break;}
    else if(a==88&&e==88&&i==88) {++puan1;break;}
    else if(g==88&&e==88&&c==88) {++puan1;break;}
  if(tur==10){break;}  
  
  while(1){
   if(kisi==2){ikinci=ticktacktoe(a,b,c,d,e,f,g,h,i,oyuncu2,tur);}
   if(zorluk==1){ikinci=bilgisayarkolay(10,1);}
   if(zorluk==2){ikinci=bilgisayarorta(10,1,birinci);}
   if(zorluk==3){ikinci=bilgisayarzor(10,1,birinci);}
   if(zorluk==4){ikinci=bilgisayarimkansiz(10,1,birinci);}
   if(ikinci==1&&a!=79&&a!=88) {a=79;break;}
   else if(ikinci==2&&b!=79&&b!=88) {b=79;break;}
   else if(ikinci==3&&c!=79&&c!=88) {c=79;break;}
   else if(ikinci==4&&d!=79&&d!=88) {d=79;break;}
   else if(ikinci==5&&e!=79&&e!=88) {e=79;break;}
   else if(ikinci==6&&f!=79&&f!=88) {f=79;break;}
   else if(ikinci==7&&g!=79&&g!=88) {g=79;break;}
   else if(ikinci==8&&h!=79&&h!=88) {h=79;break;}
   else if(ikinci==9&&i!=79&&i!=88) {i=79;break;}                         
   else {cout<<"Hatali giris yaptiniz.\n";continue;}
}
   
    if(a==79&&b==79&&c==79) {++puan2;break;} 
   else  if(d==79&&e==79&&f==79) {++puan2;break;} 
   else  if(g==79&&h==79&&i==79) {++puan2;break;}
   else  if(a==79&&d==79&&g==79) {++puan2;break;}
   else  if(b==79&&e==79&&h==79) {++puan2;break;}
   else  if(c==79&&f==79&&i==79) {++puan2;break;}
   else  if(a==79&&e==79&&i==79) {++puan2;break;}
   else  if(g==79&&e==79&&c==79) {++puan2;break;}
    }
    cout<<oyuncu1<<":"<<puan1<<endl;
    cout<<oyuncu2<<":"<<puan2<<endl;
    ++oyun;    
}

if(puan1>puan2) {cout<<oyuncu1<<" kazandi.\n";}
else if(puan2>puan1) {cout<<oyuncu2<<" kazandi.\n";}
else if(puan1==puan2) {cout<<"Berabere.\n";}
cin.ignore();
cin.get();
}
Your code would be much easier to understand, and debug, if you would adopt a sensible, consistent indentation style. This would help you see the flow of control and logic in your code much more easily.

i know it is not easy to understand but if you say where you understand i can explain, please i need help
No it's not that we don't understand it, it's that your code as no coding style really

I recommend you following a coding style seems like you're using this style http://geosoft.no/development/cppstyle.html#Layout%20of%20the%20Recommendations , so follow those guidelines.

Also using white space to space out statements would help. For example,
1
2
3
4
5
// This
else if(birinci==2&&b!=79&&b!=88) {b=88;++tur;break;}

// Could be this
else if(birinci == 2&&b != 79&&b != 88) {b = 88; ++tur; break;}
thanks for your recommend i will try that next time (:
and good news i solve my problem thx for everyone.
if anyone want i can share the corrected code.
note:sorry for my english
That's good news! I hope you have a wonderful time in the future programming. By the way, your English is a lot better than you think.

You write better than many NATIVE speakers. :P
thank you my friend
Topic archived. No new replies allowed.