Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6593023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:37:45+00:00 2026-05-25T17:37:45+00:00

I’m trying to code a Bingo Board in C++, but I’m doing something very

  • 0

I’m trying to code a Bingo Board in C++, but I’m doing something very wrong. I’m not sure what, but for whatever reason when I initialize the number of rows and columns, and do a nested for loop on the arrays I created to implement this structure, I get what appears to be more than a hundred rows and 30+ columns, when I should just be getting a five, by five board. I’m also trying to specify a max and min value for my rand function, but it appears that there isn’t a way to do this. Thus, what would be the best approach to accomplish this without giving away the solution? The reason why I mention that last bit is so I can learn how to do this lol.

Here is my code:

#ifndef BOARD_H
#define BOARD_H
#include <cstdlib>
#include <time.h>
#include <stdio.h>

class Board
{
public:
    Board(unsigned int numberOfRows, unsigned int numberOfColumns, unsigned int seed, unsigned int max, unsigned int min);
    void generate();
        void setSeedValue(int seed);

private:
   unsigned int m_rows[];
   unsigned int m_columns[];
   unsigned int m_max, m_min;
};

#endif // BOARD_H

    Board::Board(unsigned int numberOfRows, unsigned int numberOfColumns, unsigned int seed, unsigned int max, unsigned int min)
{
    this->m_rows[numberOfRows];
    this->m_columns[numberOfColumns];
    srand(seed);
    this->m_max = max;
    this->m_min = min;
    printf("%d\n", size_t(m_rows));
    printf("%d\n", size_t(m_columns));
}

void Board::generate()
{
    for (int i = 0; i < size_t(m_rows); i++)
    {
        for(int j = 0; j < size_t(m_columns); j++)
        {
            this->m_columns[j] = (rand() % 10) + j;

            std::cout << this->m_columns[j];
        }
    }
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    Board * board = new Board(5, 5, time(NULL), 100, 1);

    board->generate();

    delete board;

    return a.exec();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:37:46+00:00Added an answer on May 25, 2026 at 5:37 pm

    In order to create the 2-dimensional board your wanting, where the size is input at runtime, you’re going to have to actually dynamically allocate a board in memory … you can’t declare your board the way you’ve done in your class as zero-length arrays.

    Code like this:

    this->m_rows[numberOfRows];
    

    does not initialize your array-size … rather it actually attempts to access memory allocated at that offset from the start of m_rows … that could cause a segmentation fault or some other undefined behavior due to accessing memory beyond the end of the class/structure type.

    It would be much better, since you’re using C++, to create your board class using the STL’s std::vector container. Your Board class would then look like the following:

    class Board
    {
        public:
            Board(unsigned int numberOfRows, unsigned int numberOfColumns, 
                  unsigned int seed, unsigned int max, unsigned int min);
    
            void generate();
            void setSeedValue(int seed);
    
        private:
           vector<vector<unsigned int> > board; //use the STL vector container
           unsigned int m_max, m_min;
    };
    

    Then in your constructor, you would actually allocate the necessary memory (through the STL’s vector container) that your board will take up:

    Board::Board(unsigned int numberOfRows, unsigned int numberOfColumns, 
                 unsigned int seed, unsigned int max, unsigned int min)
    {
        for (int i=0; i < numberOfRows; i++)
        {
            this->board.push_back(vector<unsigned int>(numberOfColumns, 0));
        }
    
        srand(seed);
        this->m_max = max;
        this->m_min = min;
        printf("%d\n", size_t(m_rows));
        printf("%d\n", size_t(m_columns));
    }
    

    Finally, your Board::generate function would now look like the following:

    void Board::generate()
    {
        for (int i = 0; i < this->board.size(); i++)
        {
            for(int j = 0; j < this->board[i].size(); j++)
            {
                this->board[i][j] = (rand() % 10) + j;
    
                std::cout << this->board[i][j];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.