0

i am working on XO game with c++ but i have a problem

cout<<"please enter the field number For O"<<endl;
cin.get(a);

if (a=='1')
    arr[0][0] = 'O';
else if (a=='2')
    arr[0][1] = 'O';
else if (a=='3')
    arr[0][2] = 'O';
else if (a=='4')
    arr[0][3] = 'O';
else if (a=='5')
    arr[0][4] = 'O';
else if (a=='6')
    arr[1][0] = 'O';

the problem here is when i try to enter a number bigger then 9, for example 15, the program reads it 1 and 5 so it applies two conditions at once, i tried to use get

cin.get(a);

but it gave me the same result

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
Ashraf Eldawody
  • 138
  • 3
  • 11

1 Answers1

0

When you just use "cin" it takes one character especially in the case of an integer. If you want it to take your whole input then consider using "getline(cin,a)" i think that will fix your problem.