I am a bit confused as to why my program won't execute. It runs the code and immediately terminates. Also, for my void printboard function, is there a way to return the board?
#include <iostream>
using namespace std;
int main()
{
bool checkboard (int myarray[3][3], bool decider1);
bool winorlose(int myarray[3][3], bool decider2);
bool decider1;
bool decider2;
char person1 = 'X';
char person2 = 'O';
int x;
int y;
int a;
int b;
char myarray[3][3];
cout << "In real life, play Rock,paper or scissors to see who goes first." << endl;
function checkWin(x, y) {
var s = 0;
for (var i = 0; i != 3; i++) { // checking rows
s += field[y][i];
}
if (Math.abs(s) == 3) {
return s;
}
s = 0;
for (i = 0; i != 3; i++) { // checking columns
s += field[i][x];
}
if (Math.abs(s) == 3) {
return s;
}
if (x == y) { // checking one diagonal
s = 0;
for (i = 0; i != 3; i++) {
s += field[i][i];
}
if (Math.abs(s) == 3) {
return s;
}
}
if (x + y == 2) { // checking second diagonal
s = 0;
for (i = 0; i != 3; i++) {
s += field[2 - i][i];
}
if (Math.abs(s) == 3) {
return s;
}
}
return 0;
}
Though the code should be more laconic if the check of if (Math.abs(s) == 3) is moved to the end from 4 branches.
yes, both of your codes make sense, but i am unsure why my code does not run. for my printboard function, i tried putting printboard(...); in the main function, but the parameters i had didn't work, said something like i needed a bracket in it.