Question

bool update(char userInput){ int i = board_height - 1; int j = userInput - 'A'; while(i>=0){...

bool update(char userInput){

int i = board_height - 1;

int j = userInput - 'A';

while(i>=0){ if(board[i][j] == ' '){

board[i][j] = next;

if(checkRow(i,j,next) || checkColumn(i,j,next) || checkLeftDiagonal(i,j,next) || checkRightDiagonal(i,j,next)){

global_state = next - '0';

} if(next == '1'){

next = '2';

}else{

next = '1';

} break;

} i--;

} if(i == -1){

return false; }

return true;

}

How can this be turned into int update instead of bool update

Homework Answers

Answer #1
// chaged return type to int
int update(char userInput){

int i = board_height - 1;

int j = userInput - 'A';

while(i>=0){ if(board[i][j] == ' '){

board[i][j] = next;

if(checkRow(i,j,next) || checkColumn(i,j,next) || checkLeftDiagonal(i,j,next) || checkRightDiagonal(i,j,next)){

global_state = next - '0';

} if(next == '1'){

next = '2';

}else{

next = '1';

} break;

} i--;

} if(i == -1){
// here false means 0 so we can return 0
return 0; }
// here true means 1 so we can return 1
return 1;

}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

Please Like and Support me as it helps me a lot

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Design flow chart on software not handwritten. void claimProcess() {    int id;    bool found...
Design flow chart on software not handwritten. void claimProcess() {    int id;    bool found = false;    system("cls");       printf("Enter user ID for which you want to claim insurrence: ");    scanf("%d", &id);    int i;    for (i = 0; i < userCount; i++)    {        if (users[i].id == id)        {            found = true;            break;        }    }    if (found == false)   ...
Consider the following variable definitions: char a, *b, *c; int d[2], *e; int i, *j; How...
Consider the following variable definitions: char a, *b, *c; int d[2], *e; int i, *j; How many total bytes does this code allocate for variables?  Assume a 32-bit representation for integer and pointer values. a     sizeof(char) b     sizeof(char *) c     sizeof(char *) d    2*sizeof(int) e     sizeof(int *) i     sizeof(int) j     sizeof(int *) Total number of bytes ? What is the output of the following piece of code? (Use the above variable definitions). j = &i; *j = 50;                      /* i = 50 */ e = &d[0]; *e...
int main() { int i, j, sum = 0; for(i=0;i<3;i++) { for(j=0;j<4;j++) { if(j > 2)...
int main() { int i, j, sum = 0; for(i=0;i<3;i++) { for(j=0;j<4;j++) { if(j > 2) break; sum++; } } } What is value of sum, explain.
Define a recurrence F(n) for the code: int a(int i, int j){ if( j <= 1)...
Define a recurrence F(n) for the code: int a(int i, int j){ if( j <= 1) return i+20; else return j + a(i+10, j-3); } This recurrence I've come up with is F(n) = 2 if j <= 1 and F(n) = 2 + F(i+10, j-3). Now I need to solve this recurrence and represent it in big O notation which I'm unsure how to do. The main thing throwing me off is that there are two variables in the...
#include<iostream> using namespase std; int main() {     int i=1;     int j=-5;     int k=80;...
#include<iostream> using namespase std; int main() {     int i=1;     int j=-5;     int k=80;     float f=2.22;     float h=-7.5;     char a='S';     char b='M';     cout<<i<<"\t"<<j<<"\t"<<k<<endl;     Cout<<f<<"\t"<<h<<endl;     cout<<a<<"\t"<<b<<endl;     return 0;     }
#include #include #define MAX_SIZE 1300 // Maximum string size int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE];...
#include #include #define MAX_SIZE 1300 // Maximum string size int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE]; printf("Enter any string: "); gets(str); printf("Enter word to search occurrences: "); gets(tosearch); int cursor = 0; int i = 0; int stringLen = 0; int searchLen = 0; int count1; int count2; stringLen = strlen(str); searchLen = strlen(tosearch); count1 = 0; count2 = 0; for (cursor = 0; cursor <= stringLen; ) { if (str[cursor] == tosearch[i]) { count1++; if (count1 == searchLen) {...
The code I have so far:    public static boolean validPass(String sPass)    {    boolean...
The code I have so far:    public static boolean validPass(String sPass)    {    boolean y=false;    if(sPass.length()>10)    {    int i,j=0,k=0;    char c;    for(i=0;i<sPass.length();i++)    {              c=sPass.charAt(i);    if(c>='A' && c<='Z')    {    j++;    }    else if(c>='a' && c<='z');    else if (!(sPass.contains("&") || sPass.contains("-")    || sPass.contains("%") || sPass.contains("_")    ||sPass.contains("^")||sPass.contains("@")));    else if(c>='0' && c<='9')    {    k++;    }    else    {   ...
True or False? a. int i = 0; while(i <= 20); { i = i+5; cout...
True or False? a. int i = 0; while(i <= 20); { i = i+5; cout << i << " "; } The above loop is an infinite loop. for(int i =5; i>=1 ; i++) { cout << i << endl; } The above loop is an infinite loop.
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete....
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete. Return true or false to indicate success or failure. Delete the memory the node was using The algorithm for deleting a Node to a Linked List (general case): ● Begin at the head. ● Compare the id to the current node. ● If search id > current id, stop. ● Detach the current Node ○ current->previous->next = current->next ○ current->next->previous = current->previous ● Deallocate...
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char...
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char **argv) { const int BUF_LEN = 128; char str[BUF_LEN]; int i; char c; int is_binary; int d, n; /* Get the user to enter a string */ printf("Please enter a string made of 0s and 1s, finishing the entry by pressing Enter.\n"); for (i=0; i<BUF_LEN-1; i++) { scanf("%c", &c); if (c == '\n') { break; } str[i] = c; } str[i] = '\0'; /*...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT