我的 CIN 命令完全跳过输入?我什么都试过了

My CIN command skips input entirely? I've tried everything

本文关键字:什么 过了 输入 命令 CIN 我的      更新时间:2023-10-16
#include <iostream>
#include <ctime>
#include <limits>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
     int a, b;
     int I, P;
     unsigned int x;
     unsigned int y;
     int n, m;
     unsigned int X, O;
     int tictac[3][3] = {
        {1, 1, 1},
        {1, 1, 1} ,
        {1, 1, 1} };
      cout << "Player 1, enter X or O:" << endl;
      cin >> a;
      while (a == X);
      {
          cout << "Now, fill in the desired coordinated in a 3x3 square, a[x][y]"    << endl;
          cout << "Enter 'x' in [x]" << endl;
          cin.ignore (std::numeric_limits<std::streamsize>::max(), 'n');
          cin >> x;
          cout << "Enter 'y' in [y]" << endl;
          cin.ignore (std::numeric_limits<std::streamsize>::max(), 'n');
          cin >> y;
          tictac[x][y] == X;
      }
}

我正在编写一个程序,让2名玩家在3x3网格上玩tictactoe,而其余的"CIN"命令拒绝接受输入。

我尝试将"CIN"命令更改为:

getline (cin, x)
getline (cin, y)

尝试将变量从(Unsigned int(更改为(Signed int(,并使用cin.ignore((命令,但问题仍然存在。

 unsigned int X, O;
 int tictac[3][3] = {
    {1, 1, 1},
    {1, 1, 1} ,
    {1, 1, 1} };
  cout << "Player 1, enter X or O:" << endl;
  cin >> a;
  while (a == X);

在最后一行中,X还没有初始化,所以您将a的值与任何特定值进行比较。此外,末尾的分号使循环重复一个空语句。

      tictac[x][y] == X;

这是一个你丢弃了其结果的比较。使用=进行分配。