I'm so new to arrays, I've read, I've made boxes...and yet I'm still clueless. So my task is to make a bingo card, so far I've made one column of numbers that don't repeat...something I'm very proud of, but to do that same thing with different ranges for 4 more columns with bingo across the top...that's where i get lost. B column range is 1-15, I 16-30, N 31-45...with a free spot in location [2,3] G 46-60, and O 60-75. so far this is wat I hav
thanx so much to anyone willing to help!!

``````#include <iostream>
//put additional include lines here as needed
//include <packageName>

using namespace std;

int cardNums(int array[5][5])
char bingoGrid(char bingoCard[5])

{

char bingoCard[5] {'B', 'I', 'N','G', 'O' }

{
int array[6][5];
for(int i = 0 ;i < 15 ; i++)
array[i] = 0;

srand((unsigned)time(0));
int random_integer;
int lowest=1, highest=15;
int range=(highest-lowest)+1;
for(int index=0; index<5;)
{
random_integer = lowest+rand()/(RAND_MAX/(highest-lowest) + 1);
if(array[random_integer-1] == 0)
{
array[random_integer-1] = 1;
cout << random_integer << endl;
index++;
}

}
}
}

int main()
{
char bingoGrid(bingoCard)endl;
int cardNums(array [5][5])endl;

return 0;
}
``````

``````tags for readability.

[code=cpp]
#include <iostream>
//put additional include lines here as needed
//include <packageName>

using namespace std;

int cardNums(int array[5][5])
char bingoGrid(char bingoCard[5])

{

char bingoCard[5] {'B', 'I', 'N','G', 'O' }

{
int array[6][5];
for(int i = 0 ;i < 15 ; i++)
array[i] = 0;

srand((unsigned)time(0));
int random_integer;
int lowest=1, highest=15;
int range=(highest-lowest)+1;
for(int index=0; index<5; index++)
{
random_integer = lowest+rand()/(RAND_MAX/(highest-lowest) + 1);
if(array[random_integer-1] == 0)
{
array[random_integer-1] = 1;
cout << random_integer << endl;
index++;
}

}
}
}

int main()
{
char bingoGrid(bingoCard)endl;
int cardNums(array [5][5])endl;

return 0;
}``````
``````#include <iostream>
//put additional include lines here as needed
//include <packageName>

using namespace std;

int cardNums(int array[5][5])
char bingoGrid(char bingoCard[5])

{

char bingoCard[5] {'B', 'I', 'N','G', 'O' }

{
int array[6][5];
for(int i = 0 ;i < 15 ; i++)
array[i] = 0;

srand((unsigned)time(0));
int random_integer;
int lowest=1, highest=15;
int range=(highest-lowest)+1;
for(int index=0; index<5
{
random_integer = lowest+rand()/(RAND_MAX/(highest-lowest) + 1);
if(array[random_integer-1] == 0)
{
array[random_integer-1] = 1;
cout << random_integer << endl;
index++;
}

}
}
}

int main()
{
char bingoGrid(bingoCard)endl;
int cardNums(array [5][5])endl;

return 0;
}``````

Line 7: Is this a function? A function declaration? If it's a function declaration, it needs a semicolon. If it's a function, it needs to have brackets.

Line 15: If a bingo card is 5 x 5, why have you declared a 6 x 5 array?
Line 17 and elsewhere: If you have declared "array" to be 2 dimensional, you should be referencing it as a 2-Diminensional array, not a 1-Dimensiona array.

Lines 39 and 40 - You have written these function calls as function declarations. Leave the variable types off, and why do you have "endl" without a "cout" statement?

yes line 7 is a function...and doesn't it hav brackets, unless it's the whole thing that's in brackets? I changed the array dim to [5][5] told u I'm new and I'm just goin by my flowchart

i get an initializor error everytime I compile...i'm using c++, also I don know how to post the way you would like. i'll do it if u show me

int cardNums(int array[5][5])
char bingoGrid(char bingoCard)

{

char bingoCard[]
bingoCard[0]='B';
bingoCard[1]='I';
bingoCard[2]='N';
bingoCard[3]='G';
bingoCard[4]='O';

For one thing, it will probably complain about not having the brackets by the funtion on line 7. Even if nothing is being done in the function you need the open/close brackets and probably the return for it to compile.

Alternatively, if you're not ready to use that function, just comment that line out for now. Can you post the errors you're getting from the compiler?

And in order to post the code correctly, put [ code=cpp] at the beginning of your code and [/ code] at the end. Without the spaces after the first bracket.

To add line numbers, highlight C++ syntax, and preserver formatting, do this:

[code=cplusplus] // paste your code here. Line numbers will be added, formatting preserved.

[/code]

If you don't want the line numbers or the syntax highlighting, but do want the formatting preserved, do this:

[code]

[/code]

``int cardNums(int array[5][5])``

If this is a function declaration, it needs to have a semicolon at the end of this line. If it is the function itself, it needs to be like this:

``````int cardNums(int array[5][5])
{
return 0;   // 0 is just an integer needed to make it compile.
// change it when you actualy write the function.
}``````
``````char bingoCard[]   // change this line to: char bingoCard[5];
bingoCard[0]='B';
bingoCard[1]='I';
bingoCard[2]='N';
bingoCard[3]='G';
bingoCard[4]='O';``````
``````#include <iostream>
//put additional include lines here as needed
//include <packageName>

using namespace std;

int cardNums(int array[5][5]) //this is a func
char bingoGrid(char bingoCard) //this is a func, this is my error expected initializor before 'char'

{

char bingoCard[5] //an array
bingoCard[0]='B';
bingoCard[1]='I';
bingoCard[2]='N';
bingoCard[3]='G';
bingoCard[4]='O';

{
int array[5][5]; //an array
for(int i = 0 ;i < 15 ; i++)
for(j=0;j<5;j++)
array[i][j] = 0;

srand((unsigned)time(0));
int random_integer;
int lowest=1, highest=15;
int range=(highest-lowest)+1;
for(int index=0; index<5;)
{
random_integer = lowest+rand()/(RAND_MAX/(highest-lowest) + 1);
if(array[random_integer-1][random_integer-1] == 0)
{
array[random_integer-1][random_integer] = 1;
cout << random_integer << endl;
index++;
}

}
}
return 0;
}

int main()
{
bingoGrid(bingoCard)endl;
cardNums(array [5][5])endl;

return 0;
}``````

Judging from your error I'd say it's because you don't have the brackets for the function on line 8. Since you're not ready to use it yet, just comment that line out and see if it compiles.

so this declaration, do you mean the for loop? I jus want a function called cardNums that will give me an array of [5][5] for lines 21-38? can this be done or is my flowchart off?
thanx sooo much

It's a little off. If you're going to pass an array in to the function, that's one thing, but if you do that, don't redeclare the array as you do on line 21. And if you're passing it in, you need to declare it before you do the passing in main. Your function calls in main are also off. You need to be setting them equal to something, or outputting them. If you're setting them equal, take off the endl at the end, and if you're outputting, add cout and the <<.

Also, you might want to consider actually making your array have a name that means something. It's trivial with a program this small, but it's good programming practice for once you get to writing larger programs.

yes I want to pass the array to my function, but how do I pass it for a 2d array with random int in both rows and cols. I only have the range not exact values?

You could either just initialize everything to 0 before you pass it, and do the random generation in the function and replace the 0's, or you could just randomly generate the numbers before you pass the array to the function.

Edit - Off to grab lunch so if you ask a question, I won't be back for 30 minutes to answer. Just an FYI.

what is wrong with my functions?

``````int cardNums(int (array)[5][5], int i, int j) //this is a func
char bingoGrid(char (bingoCard)[5], char 'B', char 'I', char 'N', char 'G', char 'O')//this is a function``````

Brackets must always appear after a function header to signal that a body exists, even if one doesn't!

I believe that when you pass a 2D array you have to declare it as array[][5]...also, why did you put parens around your arrays?

Are you getting errors? What do they say?

And as Joatmon said, and I've said multiple times in this thread =P, add the brackets for the functions.

He was thinking you were talking about the square brackets in use by the array I think. So I hope actually showing that it needs curly brackets {} will make him see what we mean :D

it did thx curly brackets will be the death of me..or arrays, so these are my errors

``````int array[5][5]; //an array to print out 1 col of random numbers

for(int i = 0 ;i < 15; i++)//
for(j=0;j< 5;j++)//bingo.cpp:17: error: expected unqualified-id before â€˜forâ€™ bingo.cpp:17: error: expected constructor, destructor, or type conversion before â€˜<â€™ tokenbingo.cpp:17: error: expected constructor, destructor, or type conversion before â€˜++â€™ token
array[i][j] = 0;//bingo.cpp:18: error: expected constructor, destructor, or type conversion before â€˜<â€™ tokenbingo.cpp:18: error: expected constructor, destructor, or type conversion before â€˜++â€™ token

srand((unsigned)time(0));//bingo.cpp:21: error: expected constructor, destructor, or type conversion before â€˜(â€™ token

int random_integer;//
int lowest=1, highest=15;//
int range=(highest-lowest)+1;//bingo.cpp:25: error: expected unqualified-id before â€˜forâ€™bingo.cpp:25: error: expected constructor, destructor, or type conversion before â€˜<â€™ tokenbingo.cpp:25: error: expected unqualified-id before â€˜)â€™ token``````

on line 4, is j already declared as an int?

It's not unless you declared it elsewhere as one. I was going to tell you that.

``````char bingoGrid(char bingoCard[5])
{
char bingoCard[5]; //an array
bingoCard[0]='B'; //assigning
bingoCard[1]='I';
bingoCard[2]='N';
bingoCard[3]='G';
bingoCard[4]='O';
}

main function ()
char bingoGrid[5];
``````

what am I missing here?

are you trying to make a function call to bingoGrid?

if so, you need to do something like bingoGrid(existingchararray[]);

char bingoGrid[5]; is interpreted by the compiler as "okay, make an array of 5 characters, and name that array bingoGrid"

but that code you have right there shows that it is clearly a function.

ok this is what I want bingoCard[5] to print out every element I assigned it to

``````card=cardNums[int 0][int 0];

char bingoCard[5]; //an array
bingoCard[0]='B'; //assigning
bingoCard[1]='I';
bingoCard[2]='N';
bingoCard[3]='G';
bingoCard[4]='O';``````

All right, you're confusing me. Is bingoGrid an array or a function in post 20? Don't try to make it both. In post 22, lines 3 through 8 look fine to me, but I have no idea what you are trying to do on line 1.

sorry line 1 shouldn't be there. line 3 is an array in the main function, it compiles but theres no output

sorry line 1 shouldn't be there. line 3 is an array in the main function, it compiles but theres no output

You don't have any cout statements so you haven't asked the program to output anything. What's the output supposed to look like? This below?

BINGO

``````int cardNums(int nums[][5]) //this is a func
{
}
int main()
{
{
int nums[5][5];
cardNums(nums);

char bingoCard[5]; //an array
bingoCard[0]='B'; //assigning
bingoCard[1]='I';
bingoCard[2]='N';
bingoCard[3]='G';
bingoCard[4]='O';

cout<<"B,", "I", "N", "G", "O"<<endl;

}

return 0;
}``````

and yes i still get errors so what's wrong, I thought I folllowed the rules for passing my array by ref...guess not

I haven't tried compiling yet, but I think your problem is:
cout<<"B,", "I", "N", "G", "O"<<endl;
do you want it to print the quotation marks?
If you want it to print BINGO use cout << "BINGO" << endl;
if you want it to print "B" "I" "N" "G" "O" then use
cout << "/"B/" /"I/" /"N/" /"G/" /"O/"" << endl;
notice the slashes are required to make the compiler know that is part of the string, not the ends of the string.

If you want BINGO but want to print it out one letter at a time, use the << operator:
cout << "B" << "I" << "N" << "G" << "O" << endl;

also make sure you #include <iostream>
and
using namespace std;

before using cout.

you are awesome!! it works it was the bottom one that I wanted. now i jus have to get my random num func goin and i'm set

``````int cardNums(int nums[][5]) //this is a func for an array, where the var a, b are going to change
{
for(int a=0; a < 5; a++)
{	for(int b=0; b < 5; b++)
{

array[a][b] = 0;//
}

}
}

int array[5][5]; //an array to print out 5col & 5rows of random numbers

srand((unsigned)time(0));

int random_integer;//for 1 col
int lowest=1, highest=15;//these variables change
int range=(highest-lowest)+1;//the range changes
for(int index=0; index <5;)//
{
random_integer = lowest+rand()/(RAND_MAX/(highest-lowest) + 1);
if(array[random_integer-1])
{
array[random_integer-1];
cout << random_integer << endl;
index++;
}

}

return 0;
}``````
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.