This is probably a really simple problem to fix and I'm stupid
Code:
#include <iostream>
#include <cstdint>
int g_difficulty;
bool g_type;
using std::cout;
using std::cin;
void setSlot(int16_t slot, int16_t &dataToSet)
{
switch (g_type)
{
case 0:
dataToSet[slot-1]=1; break;
case 1:
dataToSet[slot-1]=2; break;
}
}
void render(int16_t *gamedata)
{
for (int counter{}; counter<9; ++counter)
{
switch (gamedata[counter])
{
case 0:
cout << " "; break;
case 1:
cout << "O"; break;
case 2:
cout << "X"; break;
}
switch (counter)
{
case 0:
cout << "#"; break;
case 1:
cout << "#"; break;
case 2:
cout << "\n######\n"; break;
case 3:
cout << "#"; break;
case 4:
cout << "#"; break;
case 5:
cout << "\n######\n"; break;
case 6:
cout << "#"; break;
case 7:
cout << "#"; break;
case 8:
cout << "\n"; break;
}
}
}
int main()
{
int16_t gamedata[9]{};
cout << "TicTacToe v0.5 by Nyap\n"
<< "====================\n"
<< "1) Easy\n"
<< "2) Medium\n"
<< "3) Hard\n";
do
{
cout << "Please select a difficulty: ";
cin >> g_difficulty;
if (g_difficulty>0 && g_difficulty<4)
{
break;
}
cout << "Invalid input!\n";
cin.clear(); cin.ignore(40000, '\n');
}
while (g_difficulty<1 || g_difficulty>3);
cout << '\n';
char type;
do
{
cout << "Are you O or X?: ";
cin >> type;
if (type == 'X')
{
g_type=1; break;
}
if (type == 'O')
{
g_type=0; break;
}
cout << "Please enter 'O' or 'X' (make sure it's a capital letter)\n";
cin.clear(); cin.ignore(40000, '\n');
}
while (!(type == 'O' || type == 'X'));
cout << "====================\n"
<< "You need to enter a number from 1-9.\n"
<< "The top left of the grid is 1, the bottom right is 9.\n"
<< "To exit enter 0.\n"
<< "====================\n";
render(gamedata);
int16_t turn;
while (0)
{
cout << "Your turn: "; cin >> turn;
if (gamedata[turn]==0)
{
setSlot(turn, *gamedata);
}
}
return 0;
}
I'm getting the problem in setSlot() but I included the rest of the code just in case||=== Build: Debug in TicTacToe (compiler: GNU GCC Compiler) ===|
/home/nyap/Projects/TicTacToe/main.cpp||In function ‘void setSlot(int16_t, int16_t&)’:|
/home/nyap/Projects/TicTacToe/main.cpp|15|error: invalid types ‘int16_t {aka short int}[int16_t {aka short int}]’ for array subscript|
/home/nyap/Projects/TicTacToe/main.cpp|17|error: invalid types ‘int16_t {aka short int}[int16_t {aka short int}]’ for array subscript|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Last edited by Nyap,