Question
my code output shows up as incorrect! when it should be correct when i type in guess 15 and guess 8, please help me fix
my code output shows up as "incorrect!" when it should be correct when i type in guess 15 and guess 8, please help me fix this. below is my code
#include
#include
using namespace std;
// declare functions
int beginGame(int arr[]);
void displayBoard(int board[][3]);
void instructions();
bool testWinner(int ans, int boardnum, int ansBoard[]);
// main function
int main()
{
// initialized 2D array of integers as Board
int board1[4][3] ={38,11,83,
15,6,33,
10,2,20,
86,NULL,95 };
int board2[4][3] ={28,10,55,
89,17,98,
22,4,31,
69,NULL,78 };
int board3[4][3] ={90,9,45,
66,12,48,
34,7,70,
44,NULL,26 };
// ansboard
int ansBoard[3] = {14,15,8};
int usedboard[3]={NULL};
// count the no. of right guess
int count = 0 ;
// diaplay instructions
instructions();
// display board 1
displayBoard(board1);
// take guess
int guess1 = beginGame(usedboard);
// check ans
bool ans1 = testWinner(guess1, 0, ansBoard);
// print review
if(ans1 == true)
{
count++;
cout<<"You are a Number Genius!! ";
}
else{
cout<<"I am Sorry , That was Incorrect!! ";
}
// display board 2
displayBoard(board2);
// take guess
int guess2 = beginGame(usedboard);
// check ans
bool ans2 = testWinner(guess2, 0, ansBoard);
// print review
if(ans2 == true)
{
count++;
cout<<"You are a Number Genius!! ";
}
else{
cout<<"I am Sorry , That was Incorrect!! ";
}
// display board 3
displayBoard(board3);
// take guess
int guess3 = beginGame(usedboard);
// check ans
bool ans3 = testWinner(guess3, 0, ansBoard);
// print review
if(ans3 == true)
{
count++;
cout<<"You are a Number Genius!! ";
}
else{
cout<<"I am Sorry , That was Incorrect!! ";
}
// print all ans review
if(count == 3){
cout<<"**** You are Number Guessing Champion ... CONGRATUTAIONS.....*** ";
}
else{
cout<<"Sorry You are out of Guesses.... ";
}
cout<<"Do you want to play again ?? Enter ) to exit and any other number to continue...";
return 0;
}
// begingame starts game and take random guess form user
int beginGame(int playboard[]){
cout<<"Enter guess or 0 to exit : ";
int random;
cin>>random;
// if guess is 0 then exit
if(random == 0){
return 0;
}
// if guess is less than 0 then again ask usser for input
while(random < 0){
cout<<"Please Enter Whole numbers : ";
cin>> random;
if(random > 0){
break;
}
}
return random;
}
// display board
void displayBoard(int board[][3]){
int m = 4;
int n = 3;
// using nested loops
for(int i=0; i for(int j=0; j if(board[i][j] == 0){ cout<<"? "; } else{ cout< } } cout<<" "; } } // printinstructions void instructions(){ cout<<"***************************************************** "; cout<<" MISSING NUMBER GAME "; cout<<" A fun brain game...... "; cout<<" Plaese Enter a Whole number to Guess the Missing Number.... "; cout<<" Program developed by : john Doe "; cout<<"***************************************************** "; } // return true if a sn is correct otherwise return false bool testWinner(int ans, int boardnum, int ansBoard[]){ if(ansBoard[boardnum] == ans){ return true; } else{ return false; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started