I am trying to make my loop ask for user input 8 times.... also if character has
ID: 3925366 • Letter: I
Question
I am trying to make my loop ask for user input 8 times....
also if character has been inputted previously, it should only show available characters and ask for user input again if character is not available anymore.
62 //move should be one of 9 characters 'A' to 'I', player should be 'X' or 'O', should return true if move was successfully made at move position, false otherwise.
63 bool makeMove(char board[3][3], char move, char player)
64 {
65 int Col = 0;
66 int Row = 0;
67
68 for(Row = 0; Row < 3; ++Row)
69 {
70 for(Col = 0; Col < 3; ++Col)
71 {
72 if(board[Row][Col] == move)
73 {
74 board[Row][Col] = player;
75 print(board);
76 return true;
77 }
78 Col++; //iterate the column;
79 }
80
81 if(board[Row][Col] == move)
82 {
83 board[Row][Col] = player;
84 print(board);
85 return true;
86 }
87 Row++;
88 Col = 0; //iterate the row;
89 }
90 return false;
91 }
40 // returns 'X', 'O', or a non-winning character of your choosing
41 char winner(const char board[3][3])
42 {
43 if(board[0][0] == board[0][1] == board[0][2] ||
44 board[0][0] == board[1][1] == board[2][2] ||
45 board[0][0] == board[1][0] == board[2][0] ||
46 board[0][1] == board[1][1] == board[2][1] ||
47 board[0][2] == board[1][2] == board[2][2] ||
48 board[1][0] == board[1][1] == board[1][2] ||
49 board[2][0] == board[2][1] == board[2][2] ||
50 board[0][2] == board[1][1] == board[2][0])
51 {
52 cout << " The winner is " << board[0][0];
53 return board[0][0];
54 }
55 else
56 {
57 cout << " There is no winnner " << endl;
58 return !board[0][0];
59 }
60 }
//create an array called moves
char moves[] = "ABCDEFGHI";
int i = 0; for(int i = 0; i < 9; i++) {
//prompt next player to make move.
cout << " Enter a character from the list; ";
cout << moves << " ";
cin >> move;
makeMove(board,move,player); }
return winner(board);
}
Explanation / Answer
String items[8] ,n;
while (num <=8)
{
cin >> n;
for(i=0;i<items.length;i++)
{
if (items[i]==n)
{
cout << "Error - you entered already this item." << endl;
}
else
}
for(int i=items.length;i<items.length+1;i++)
{
items[i]=n;
}
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.