Have created a simple bingo game, I'm going to add color later (why I have used the SetConsoleTextAttribute). The problem is that the X i replaced by 88, I know why (I think), it's becuse it's a int and not a char, but when i tried to put in (char) before the Number[1] = 'X';
it doesn't work

#include <iostream>
#include <time.h>
#include <windows.h>

using namespace std;
HANDLE SetColor(
                HANDLE console,
                       int fg = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
                       int bg = 0)
                       {
                       if(console == NULL);
                       console = GetStdHandle(STD_OUTPUT_HANDLE);
                       SetConsoleTextAttribute(console, fg | bg);
                       return console;
                       }
                       
int main()
{
doubleNumber[16];
char StrikeHit('X');
srand(time(0));
bool GameOver(false);
bool GameOverWin(false);

cout << "enter 16 numberss between 10-40" << endl;
cin >> Number[0];
cin >> Number[1];
cin >> Number[3];
cin >> Number[4];
cin >> Number[5];
cin >> Number[6];
cin >> Number[7];
cin >> Number[8];
cin >> Number[9];
cin >> Number[10];
cin >> Number[11];
cin >> Number[13];
cin >> Number[13];
cin >> Number[14];
cin >> Number[15];

int k = 51;
while(k) {
do {
       cout << "-+-+-+-+-+-+-" << endl;
        cout << "|" << Number[0] << "|" << Number[1] << "|" << Number[2] << "|" << Number[3] << "|" << endl;
        cout << "-+-+-+-+-+-+-" << endl;
        cout  << "|" << Number[4] << "|" << Number[5] << "|" << Number[6] << "|" << Number[7] << "|" << endl;
        cout << "-+-+-+-+-+-+-" << endl;
        cout  << "|" <<  Number[8] << "|" << Number[9] << "|" << Number[10] << "|" << Number[11] << "|" << endl;
        cout << "-+-+-+-+-+-+-" << endl;
        cout  << "|" <<  Number[12] << "|" << Number[13] << "|" << Number[14] << "|" << Number[15] << "|" << endl;
        cout << "-+-+-+-+-+-+-" << endl;
        bool bValidMove;

do  {
            int randNumber = rand() % 41 + 10;
            bValidMove = true;
            
            if(randNumber == Number[0] && Number[0] !='X'){
                          Number[0] = 'X';
                          }
            if(randNumber == Number[1] && Number[1] !='X'){
                          Number[1] = 'X';
                          }
            if(randNumber == Number[2] && Number[2] !='X'){
                          Number[2] = 'X';
                          }
            if(randNumber == Number[3] && Number[3] !='X'){
                          Number[3] = 'X';
                          }
            if(randNumber == Number[4] && Number[4] !='X'){
                          Number[4] = 'X';
                          }
            if(randNumber == Number[5] && Number[5] !='X'){
                          Number[5] = 'X';
                          }
            if(randNumber == Number[6] && Number[6] !='X'){
                          Number[6] = 'X';
                          }
            if(randNumber == Number[7] && Number[7] !='X'){
                          Number[7] = 'X';
                          }
            if(randNumber == Number[8] && Number[8] !='X'){
                          Number[8] = 'X';
                          }
            if(randNumber == Number[9] && Number[9] !='X'){
                          Number[9] = 'X';
                          }
            if(randNumber == Number[10] && Number[10] !='X'){
                          Number[10] = 'X';
                          }
            if(randNumber == Number[11] && Number[11] !='X'){
                          Number[11] = 'X';
                          }
            if(randNumber == Number[1] && Number[1] !='X'){
                          Number[1] = 'X';
                          }
            if(randNumber == Number[12] && Number[12] !='X'){
                          Number[12] = 'X';
                          }
            if(randNumber == Number[12] && Number[12] !='X'){
                          Number[12] = 'X';
                          }
            if(randNumber == Number[13] && Number[13] !='X'){
                          Number[13] = 'X';
                          }
            if(randNumber == Number[14] && Number[14] !='X'){
                          Number[14] = 'X';
                          }
            if(randNumber == Number[15] && Number[15] !='X'){
                          Number[15] = 'X';
                          }
            }
            while(!bValidMove);
            
            if(Number[1] == Number[0] && Number[2] == Number[0] && Number[3] == Number[0]) {
                         GameOverWin = true;
                         }
            if(Number[4] == Number[0] && Number[8] == Number[0] && Number[12] == Number[0]) {
                         GameOverWin = true;
                         }
            if(Number[7] == Number[3] && Number[11] == Number[3] && Number[15] == Number[3]) {
                         GameOverWin = true;
                         }
            if(Number[13] == Number[12] && Number[14] == Number[12] && Number[15] == Number[12]) {
                         GameOverWin = true;
                         }
            if(Number[5] == Number[1] && Number[9] == Number[1] && Number[13] == Number[1]) {
                         GameOverWin = true;
                         }
            if(Number[1] == Number[0] && Number[2] == Number[0] && Number[3] == Number[0]) {
                         GameOverWin = true;
                         }
            if(Number[6] == Number[2] && Number[10] == Number[2] && Number[14] == Number[2]) {
                         GameOverWin = true;
                         }
            if(Number[5] == Number[4] && Number[6] == Number[4] && Number[7] == Number[4]) {
                         GameOverWin = true;
                         }
            if(Number[9] == Number[8] && Number[10] == Number[8] && Number[11] == Number[8]) {
                         GameOverWin = true;
                         }
            if(Number[12] == Number[3] && Number[6] == Number[3] && Number[9] == Number[3]) {
                         GameOverWin = true;
                         }
            if(Number[5] == Number[0] && Number[10] == Number[0] && Number[15] == Number[0]) {
                         GameOverWin = true;
                         }
            if(GameOver)
            {
                        cout << "-+-+-+-+-+-+-" << endl;
        cout << "|" << Number[0] << "|" << Number[1] << "|" << Number[2] << "|" << Number[3] << "|" << endl;
        cout << "-+-+-+-+-+-+-" << endl;
        cout  << "|" << Number[4] << "|" << Number[5] << "|" << Number[6] << "|" << Number[7] << "|" << endl;
        cout << "-+-+-+-+-+-+-" << endl;
        cout  << "|" <<  Number[8] << "|" << Number[9] << "|" << Number[10] << "|" << Number[11] << "|" << endl;
        cout << "-+-+-+-+-+-+-" << endl;
        cout  << "|" <<  Number[12] << "|" << Number[13] << "|" << Number[14] << "|" << Number[15] << "|" << endl;
        cout << "-+-+-+-+-+-+-" << endl;
             cout << "BINGO!, you won congrat" << endl;
        }
        cin.get();
        cin.get();
}while(!GameOver); 
--k;
}     
cin.get();
cin.get();
return 0;
}

You could easily use a loop for things like this:

cin >> Number[0];
cin >> Number[1];
cin >> Number[3];
cin >> Number[4];
cin >> Number[5];
cin >> Number[6];
cin >> Number[7];
cin >> Number[8];
cin >> Number[9];
cin >> Number[10];
cin >> Number[11];
cin >> Number[13];
cin >> Number[13];
cin >> Number[14];
cin >> Number[15];

is replaceable by:

for(int i = 0; i < 16; i++)
  cin >> Number[i];

Edit:: Please keep in mind that Number is a character array, this means that if you enter an integer number, that it will be converted into it's ASCII equivalent, for example if you enter 65, it will be converted into A ...
Edit2:: time.h is an old-style header, replace it by ctime, so the include statement would become: #include <ctime>

cout << "enter 16 numberss between 10-40" << endl;

char mean a single character. You are trying to put two digits (characters).

char c='1';

thanx for the loop tip, I tried to make a loop before but constructed it wrong, As you can see I have changed my question a little (I discovered that I had written char instead of int) do you know the answer to my new problem?

Your numbers are all chars. cout will print them as chars, not ints. But you can't print them as ints because some of them have to be 'X', right? So use an array of strings instead of chars:

#include <iostream>
#include <string>
#include <stdlib.h>
#include <time.h>

using namespace std;

void PrintBoard(string Number[], int sz)
{
    cout << "-+-+-+-+-+-+-\n";

    for (int x = 0; x < sz; x += 4)
    {
        cout << Number[x] << '|' 
             << Number[x+1] << '|' 
             << Number[x+2] << '|' 
             << Number[x+3] << '\n';
        cout << "-+-+-+-+-+-+-" << endl;
    }
}

int main()
{
    string Number[16];
    srand(time(0));
    bool GameOver(false);
    bool GameOverWin(false);

    cout << "enter 16 numberss between 10-40" << endl;

    for (int x = 0; x < 16; ++x)
        cin >> Number[x];

    int k = 51;
    while(k) {
        do {
            PrintBoard(Number, 16);

            bool bValidMove;

            do  {
                int randNumber = rand() % 41 + 10;
                bValidMove = true;

                for (int x = 0; x < 16; ++x)
                {
                    if (Number[x] != "X" && randNumber == atoi(Number[x].c_str()))
                        Number[x] = "X";
                }
            }
            while(!bValidMove);

            // test for game over. no changes. i removed it to make the code shorter

            if(GameOver)
            {
                PrintBoard(Number, 16);
                cout << "BINGO!, you won congrat" << endl;
            }
            cin.get();
            cin.get();
        }while(!GameOver); 
        --k;
    }     
    cin.get();
    cin.get();
    return 0;
}

bValidLoop is never set to false so your bean placement is only tried once! Use else if's and use an else where you set the bValidLoop to false to try again.

I'm assuming this is more like Magic square not bingo as there aren't 75 balls (5 columns 15 balls each) and a 5x5 card with a fee space.


You can shuffle your cards! For your 16 grid card...
First set a sequential set of numbers into an array 16 elements in length.
Set each cell sequentially {0...15}. Randomize 0..15, that cell indexed gets saved, cell randomized gets copied to indexed cell, saved number gets copied to randomized cell, advance index by one. Then Randomize 16-index, and repeat.

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
^
rnd 16 = 6
6 1 2 3 4 5 0 7 8 9 10 11 12 13 14 15
   ^
rnd 15 = 4
6  5 2 3 4 1 0 7 8 9 10 11 12 13 14 15
       ^

etc. until last cell reached.
Cards are now shuffled!
-------
Now do the same thing again to create your shuffled deck of #'s to deal!
------

Now as to pattern matching.
If each card slot is a single bit #0 = 0x0001, #1 = 0x0002, etc.
Then compare your drawn numbers to the pattern.

0x0001   0x0002   0x0004    0x0008,
0x0010   0x0020   0x0040    0x0080
0x0100   0x0200   0x0400    0x0800
0x1000   0x2000   0x4000    0x8000

So a diagonal would be 0x8421
An X is 0x9669

So for every # dealt.
b |= 1 << dealt;

And for each comparison
if ((b & 0x8421) == 0x8421) then win diagonal
else if ((b & 0x9669) == 0x9669) then win X
else no winner yet!

This should drastically reduce your code size and then become data driven, not code driven!

Also on a second pass, insert the patterns into a table and merely check each pattern in the table instead of having code check each pattern. Then adding new patterns is as easy as adding a new line item!
!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.