hey guys. this segement of code is not working properly as it should. even after executing return statement, it goes on to the rest of the part of the code and executed even executes conditional statements that isn't true.
int x=1;///declared globally
enum turn{X_turn, O_turn};
struct struct_board
{
mark array_board[3][3];
turn get_turn();
void show_board();
void initialize();///to initialize all array slots to empty
void get_input();
};
turn struct_board::get_turn()
{
int a=x%2;
++x; ///increase value of x for next time
if(a==1)
{
cout<<"X_turn"<<endl;
return X_turn;
cout<<"HI this exeuted even after return";
}
elseif(a==0)
{
cout<<"HI this exeuted even after return in next connditional case";
cout<<"O_turn"<<endl;
return O_turn;
}
else
{
cout<<"%% operator not working properly";///shouldn’t hit this
}
}
int main()
{
struct_board b;
b.get_input();///just some partial code of int main.
}
#include <iostream>
usingnamespace std;
int x = 0;
bool funct()
{
int a=x%2;
++x; ///increase value of x for next time
if(a==1)
{
cout<<"X_turn"<<endl;
returntrue;
cout << "shouldn't be here\n";
}
elseif(a==0)
{
cout<<"O_turn"<<endl;
returnfalse;
}
else
{
cout<<"%% operator not working properly";///shouldn’t hit this
}
}
int main()
{
for(int i = 0; i < 10; i++)
funct();
return 0;
}