Tic-Tac-Toe problems

Hello, I need help with this Tic-Tac-Toe game. I am new to c++ and I understand I could have written this code much shorter than I did. Please dont change all the code I just need help with a few things. I need to make it so if I enter anything other than 1-9 it will give you an error not just go into an infinite loop. Please help!!


http://ideone.com/8E8Mwg

1
2
3
4
5
6
7
8
9
10
11
12
13
  int x;
  
  // ask the user to enter a number from 1-9 inclusive
  cout << "Enter a number from 1-9: "
  cin >> x;

  //check input number
  if ((x > 0) && (x < 10)) {
       //valid input, do something
  }  
  else {
       //Invalid input, give an error!
  }
You can also use a do-while loop:

1
2
3
do {
    // ask for a number
} while (/* the number is invalid */);

In this way, you don't have to give an error and terminate the program: you can simply ask the user to correct the mistake.
Topic archived. No new replies allowed.