Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,498 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,722 people online right now. Registration is fast and FREE... Join Now!




C++ random numbers in 2D array

 
Reply to this topicStart new topic

C++ random numbers in 2D array, Part of a Bingo game functions

hollis092
5 Mar, 2008 - 01:39 PM
Post #1

New D.I.C Head
*

Joined: 27 Feb, 2008
Posts: 10

CODE

//*************************** FillCard Function *******************************
void  fillCard ( int card [] [csize] )
{
      
         for ( int col = 0; col < csize; col++ )
               {
               for ( int row = 0; row < csize; row++ )
                   {
                         bool samenum = false;
                         int num1 = rand ()% 15 * col;                        
                   do{
                  
                  
                   for(int check = 0; check < row; check++)
                           if (num1 == card[check][col])
                               samenum = true;
                  
                   }while (samenum);
                   card[row][col] = num1;
                      
                  
                   }
}
}


//**************************END of FILLCARD ***********************************

//************************ DisplayCard Function *******************************
void  displayCard ( int card [][csize] )
{
      for ( int col = 0; csize < col; col++ )
{
          for ( int row = 0; csize < row; row++ )
          {
          cout << setw(5) <<card[col][row];
          cout<<endl;
        
}
}      cout << "The displayCard function has not been defined yet." << endl;
}  


I am having problems with the fillCard function and the displayCard function, I know that most of the code is correct. It is part of a Bingo game I am currently writing in C++. I have attached the source file to this post so anyone can run it and see what the problem might be. My output is blank absolutely nothing outputs right now. I may not have my loop structure set up correctly.

This post has been edited by hollis092: 5 Mar, 2008 - 01:42 PM
User is offlineProfile CardPM
+Quote Post

captainhampton
RE: C++ Random Numbers In 2D Array
5 Mar, 2008 - 01:42 PM
Post #2

Jawsome++;
Group Icon

Joined: 17 Oct, 2007
Posts: 518



Thanked: 2 times
Dream Kudos: 825
My Contributions
Where is the attatchment of the full program?
User is offlineProfile CardPM
+Quote Post

hollis092
RE: C++ Random Numbers In 2D Array
5 Mar, 2008 - 01:45 PM
Post #3

New D.I.C Head
*

Joined: 27 Feb, 2008
Posts: 10

Here is the full Code couldn't attach it...

CODE

// The Game of Bingo

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;

const int csize = 5;

void  fillCard ( int card [ ] [csize] );
void  displayCard ( int card [][csize] );
char  drawNum ( int & num, bool checkAray[] );
string  check4match ( int num, int cardAray [][csize] );
string  check4win ( int cArray [][csize] );

//********************************* MAIN FUNCTION ******************************
int main ( )
{
    int bingoCard[csize][csize] = {{0},{0}};
    bool chkArray [76] = { false };
    int row, col, num;
    bool noWin = true;
    string win;
    
    srand( time ( NULL ) );
    
    fillCard( bingoCard );

    while ( noWin )
    {
          system("cls");
          
          displayCard( bingoCard );
    
          cout << "    " << drawNum( num, chkArray ) <<  " "  << num;
          cout << endl << endl;
    
          cout << "    " << check4match( num, bingoCard ) << endl  << endl;
          
          win = check4win( bingoCard );
          
          system("pause");          
          
          if ( win == "BINGO!!" )
          {
             system("cls");
             noWin = false;
             cout <<  endl << setw(16) << win  << endl  << endl;
             displayCard( bingoCard );
             cout << endl << endl;
          }            
          else
             noWin = true;
              
    }  
    
    system("pause");
    return 0;
}
//***************************** END of Main ***********************************

//*************************** FillCard Function *******************************
void  fillCard ( int card [] [csize] )
{
      
         for ( int col = 0; col < csize; col++ )
               {
               for ( int row = 0; row < csize; row++ )
                   {
                         bool samenum = false;
                         int num1 = rand ()% 15 * col;                        
                   do{
                  
                  
                   for(int check = 0; check < row; check++)
                           if (num1 == card[check][col])
                               samenum = true;
                  
                   }while (samenum);
                   card[row][col] = num1;
                      
                  
                   }
}
}


//**************************END of FILLCARD ***********************************

//************************ DisplayCard Function *******************************
void  displayCard ( int card [][csize] )
{
      for ( int col = 0; csize < col; col++ )
{
          for ( int row = 0; csize < row; row++ )
          {
          cout << setw(5) <<card[col][row];
          cout<<endl;
        
}
}      cout << "The displayCard function has not been defined yet." << endl;
}  
//****************************** END of DISPLAYCARD ****************************

//******************************* DrawNum Function *****************************
char  drawNum ( int & num, bool checkAray[] )
{
      num = 0;
      return 'B';
}
//******************************END of DRAWNUM ********************************

//**************************** check4match Function ***************************
string  check4match ( int num, int cardAray [][csize] )
{
        return "Match check has not been defined yet.";
}
//************************* END of CHECK4MATCH ********************************

//************************* check4win Function ********************************
string  check4win ( int cArray [][csize] )
{
        return "BINGO!!";
}
//********************************* END of CHECK4WIN **************************                  



User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 08:07PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month