> std::cout << "Welcome to the lotto-bingo game\n"
Right, so create a readable program with names like
- bingoCard for a data structure
- playBingo() as the name of a function.
Why is everything a meaningless variation on 'array'. It's hard to follow whether you're doing the right thing or not.
Go through your code and eliminate all your 'array' and 'arr' and give them a meaningful name. When you can actually read what your code is doing, you might actually realise as you try to name something that what you're doing is completely dumb (and thus find the answer to your question).
checkForMatch() should return a result of some sort. The actual display of the outcome should be in another function. Keep functions short, with a clearly defined purpose.
1 2 3 4 5 6 7 8 9
|
do{
array = new int* [size];
for (int i = 0; i < size; i++){
array[i] = new int[size];
}
if (array == nullptr){
std::cout << "Allocation failed\n";
}
} while (array == nullptr);
| |
1. It's too late to check for array == nullptr, when you've already been busy using array[i].
2. You can generally assume that if new returns nullptr, that it's always going to return nullptr if you keep asking for the same size. Your while loop is kinda redundant.
3. The usual convention is to output error messages on std::cerr.