Hiya.

I'm a complete C++ noob. I'm trying to make a bingo game where the computer gives the user eight numbers and the user slowly plays a game of bingo.

It's very much work in progress.

However, I'm having a problem when trying to compile it, the program seems to be confused by the inclusion of 'do' in the middle of a statement. This is on line 64. Another two error messages I'm receiving is that my syntax is incorrect on lines 74 and 78 with regards to the boolean variables. Anyway, and help would be greatly appreciated.

Thanks.

#include <iostream>
#include <ctime>

void main() {

		using namespace std;

	time_t t;
	time(&t);
	srand(t);

	// Initialising the eight choices.
	int iChoice1;
	int iChoice2;
	int iChoice3;
	int iChoice4;
	int iChoice5;
	int iChoice6;
	int iChoice7;
	int iChoice8;
	int iGoodNumber;
	char cMark = 'X';
	bool bGameOver; false;
	bool bGoodNumber; false;

	iChoice1 = (rand() % 9);
	iChoice2 = (rand() % 9);
	iChoice3 = (rand() % 9);
	iChoice4 = (rand() % 9);
	iChoice5 = (rand() % 9);
	iChoice6 = (rand() % 9);
	iChoice7 = (rand() % 9);
	iChoice8 = (rand() % 9);

	if (iChoice1 == 0 || iChoice2 == 0 || iChoice3 == 0 || iChoice4 == 0 || iChoice5 == 0 || iChoice6 == 0 || iChoice7 == 0 || iChoice8 == 0) {

	iChoice1 = (rand() % 9);
	iChoice2 = (rand() % 9);
	iChoice3 = (rand() % 9);
	iChoice4 = (rand() % 9);
	iChoice5 = (rand() % 9);
	iChoice6 = (rand() % 9);
	iChoice7 = (rand() % 9);
	iChoice8 = (rand() % 9);

	}

		cout << "These are your numbers:\n" << endl;
		cout << "|----------|----------|----------|----------|" << endl;
		cout << "|          |          |          |          |" << endl;
		cout << "|    " << iChoice1 << "     |     " << iChoice2 << "    |     " << iChoice3 << "    |     " << iChoice4 << "    |        " << endl;
		cout << "|          |          |          |          |" << endl;
		cout << "|----------|----------|----------|----------|" << endl;
		cout << "|          |          |          |          |" << endl;
		cout << "|    " << iChoice5 << "     |     " << iChoice6 << "    |     " << iChoice7 << "    |     " << iChoice8 << "    |        " << endl;
		cout << "|          |          |          |          |" << endl;
		cout << "|----------|----------|----------|----------|" << endl;
		cout << "\nThe computer will now keep generating random \nnumbers between 1 and 8 until all of your \nnumbers have been generated.\n\n" << endl; 
		
// Main game loop.
		do {
			
			// Wait for a number between 1 and 8 to be generated.
			iGoodNumber = do {if ((rand() % 9) < 0) {

				bGoodNumber = true;

			}
			
			else { bGoodNumber = false;
			
			}

		} while bGoodNumber == false;

			cout << iGoodNumber << "\n"  << endl;
			
		} while bGameOver == false;
		
	
	

	system("PAUSE");

}

That's because each line you mentioned is extremely wrong.
Look up do-while loop to understand the syntax of the statement.

Oh God, how could I have failed so badly :@

Sorry for wasting your time :sad:. Even for me, this was a stupid error.

Useful tips:

you can consolidate lines 13 through 33, and eliminate lines 35 through 44 by doing this:

// Initializing the eight choices.
	int iChoice1 = (rand() % 8) + 1;
	int iChoice2 = (rand() % 8) + 1;
	int iChoice3 = (rand() % 8) + 1;
	int iChoice4 = (rand() % 8) + 1;
	int iChoice5 = (rand() % 8) + 1;
	int iChoice6 = (rand() % 8) + 1;
	int iChoice7 = (rand() % 8) + 1;
	int iChoice8 = (rand() % 8) + 1;

Furthermore, keeping your choices in array format would continue to simplify your code:

int choices[8];

for(int i=0; i<8; i++)
{
     choices[i] = (rand()%8) + 1;
}

Yeah, figured you had a brain fart and could correct it easily... :icon_wink:

Useful tips:

you can consolidate lines 13 through 33, and eliminate lines 37 through 44 by doing this:
---
Furthermore, keeping your choices in array format would simplify your code:

Assuming he's learned arrays. If not, instructor may not like it...

Useful tips:

you can consolidate lines 13 through 33, and eliminate lines 37 through 44 by doing this:

// Initializing the eight choices.
	int iChoice1 = (rand() % 8) + 1;
	int iChoice2 = (rand() % 8) + 1;
	int iChoice3 = (rand() % 8) + 1;
	int iChoice4 = (rand() % 8) + 1;
	int iChoice5 = (rand() % 8) + 1;
	int iChoice6 = (rand() % 8) + 1;
	int iChoice7 = (rand() % 8) + 1;
	int iChoice8 = (rand() % 8) + 1;

Furthermore, keeping your choices in array format would continue to simplify your code:

int choices[8];

for(int i=0; i<8; i++)
{
     choices[i] = (rand()%8) + 1;
}

This thought struck me later, but I thought that it would be harder to implement than this.

Thanks.

Assuming he's learned arrays. If not, instructor may not like it...

Instructor being 'C++ For Dummies'.
:$

Instructor being 'C++ For Dummies'.
:$

:icon_razz: plbbbbbbb..


:)

:icon_razz: plbbbbbbb..


:)

I'm gonna assume that the above post was not meant to make any sense :).

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.