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)   ...
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.
#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    {   ...
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...
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.
#include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]){ int fd1, fd2;...
#include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]){ int fd1, fd2; char buffer[100]; long int n1; if(((fd1 = open(argv[1], O_RDONLY)) == -1) || ((fd2 = open(argv[2], O_CREAT|O_WRONLY|O_TRUNC,0700)) == -1)){ perror("file problem "); exit(1); } while((n1=read(fd1, buffer, 512) > 0)) if(write(fd2, buffer, n1) != n1){ perror("writing problem "); exit(3); } // Case of an error exit from the loop if(n1 == -1){ perror("Reading problem "); exit(2); } close(fd2); exit(0); } There is an issue with this...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0 if(x<1): print('Error') exit() print('Initial value is: ',x,' ',end='') while(x!=1): if(x%2==0): x=x/2 else: x=3*x+1 count+=1 if(x!=1): rint('Next value is: ',int(x),' ',end='') else: print('Final value ',int(x),', ',end='') print('number of operations performed ',int(count),' ',end='') break
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream>...
C++ Please and thank you. I will upvote Read the following problem, and answer questions. #include<iostream> using namespace std; void shownumbers(int, int); int main() { int x, y; cout << "Enter first number : "; cin >> x; cout << "Enter second number : "; cin >> y; shownumbers(x, y); return 0; } void shownumbers(int a, int b) { bool flag; for (int i = a + 1; i <= b; i++) { flag = false; for (int j =...