What is the purpose of bool?
Oct 15, 2015 at 3:11am UTC
Hello, I just want to ask a question, as a beginner in c++ programming what is the purpose of bool? Like, can I see a sample code that illustrates what bool is for?
Oct 15, 2015 at 4:53am UTC
This code hasn't been completed nor is it close to, compiling will supply multiple errors. But it provides an example of a Boolean function. But as you code more you will find ways of implements such things.
It's used multiple times during this code, just look through it
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
#include <iostream>
#include <string>
void clearScreen()
{
for (int i = 0; i < 100; i++)
{
std::cout << std::endl;
}
}
void TTTBoardDisplay(int ticTacToeBoard[][3])
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (ticTacToeBoard[i][j] == 0)
{
std::cout << "H " ;
}
if (ticTacToeBoard[i][j] == 1)
{
std::cout << "X " ;
}
if (ticTacToeBoard[i][j] == 2)
{
std::cout << "O " ;
}
}
std::cout << std::endl;
}
}
bool winVerify(int ticTacToeBoard[][3])
{
return false ;
}
int main()
{
int ticTacToeBoard[3][3];
int errorNumber = 0;
std::string compInputCurrentPlayer = "X" ;
std::string userInputPlayerLocation;
bool compInputContinueGame = true ;
bool compInputPlayerXWin = false ;
for (int i = 0; i < 3; i++)
{ for (int j = 0; j < 3; j++)
{
ticTacToeBoard[i][j] = 0;
}
}
while (compInputContinueGame)
{
TTTBoardDisplay(ticTacToeBoard);
if (winVerify(ticTacToeBoard))
{
break ;
}
std::cout << std::endl << std::endl;
std::cout << "Player " << compInputCurrentPlayer << ", please choose a location. " ;
std::cin >> userInputPlayerLocation;
switch userInputPlayerLocation
{
case "t1" :
ticTacToeBoard[0][0] =
}
}
}
std::cout << "Congratulations " << winVerifyPlayerReturn(ticTacToeBoard) << ", you have beaten your opponent in a ferocous battle of the minds!" ;
Last edited on Oct 15, 2015 at 4:56am UTC
Topic archived. No new replies allowed.