Please, I need some help with my hw. I have to create a program that stores the scores for a football team. I need to record the score by quarter for each of the 20 games. I have to initialize all games to 0.
Then, the user is asked to enter the number of game he wants to update. The scores are created with a random number generator.

An example of the output can be like this:

Enter the number of game you wish to update: Game # 3
Do you wish to enter another game to update? If not, enter 0. Game#4
Do you wish to enter another game to update? If not, enter 0. Game#17
Do you wish to enter another game to update? If not, enter 0. Game#0

Game # Quarter 1 Quarter 2 Quarter 3 Quarter 4 Total
3 0 7 3 0 10
4 6 0 13 0 19
17 21 3 0 6 30

Final totals 123 231 321 431 345

Here is what I have so far, but I don't know what else to do :confused:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
	int game[20] [4];

	for(int g=0; g<20;g++)
		for (int q =0; q<4; q++)
			game[g] [q] = 0;
	int randomInteger;
	srand((unsigned) time(0));
	randomInteger = (rand()%33);
	
	int g;
	cout<<"Enter the number of game you wish to update: Game #";
	cin>>g;
	do
	{
		cout<<"Do you wish to enter another game to update? If not, enter 0. Game#";
		cin>>g[];
	} while (g != 0);
	cout<<"Quarter 1	"<<"Quarter 2	"<<"Quarter 3	"<<"Quarter 4"<<endl;
	for (int q = 0; q<4; q++)
		game[g-1] [q] = randomInteger;
	for (int i = 0; i<4; i++)
		cout<<game[g-1] [i]<<"		";
	cout<<endl<<endl;
	
	cin.get();
	cin.get();
	return 0;
}

Thank you for you help.

I modified your code so that it works the way that you want and changed some of your formatting so it is a bit easier to read.

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

int main()
{
	int game[20][5]; //changed to [20][5] for your total

	for( int g = 0; g < 20; g++ )
		for( int q = 0; q < 5; q++ )
			game[g][q] = 0;
			
	srand((unsigned)time(0));
	
	int randomInteger, g;
	
	cout << "Enter the number of game you wish to update: Game #";
	cin >> g;
	if( g != 0 )
	{
		for( int q = 0; q < 4; q++ ) //you had it so it was just asking for numbers and not doing anything
		{
			randomInteger = rand() % 33; //each quarter is randomly made
			game[g-1][q] = randomInteger;
			game[g-1][4] += game[g-1][q]; //for your total
		}
	}
	while( g != 0 )
	{
		cout << "Do you wish to enter another game to update? If not, enter 0. Game#";
		cin >> g;
		if( g == 0 )
			break;
		for( int q = 0; q < 5; q++ ) //same as above
		{
			randomInteger = rand() % 33;
			game[g-1][q] = randomInteger;
			game[g-1][4] += game[g-1][q];
		}
	}
	
	cout << "Quarter 1	" << "Quarter 2	" << "Quarter 3	" << "Quarter 4       " << "Total" << endl;
	for( int j = 0; j < 20; j++ ) //outputs each quarter and total for each game
		for( int i = 0; i < 5; i++ )
			cout << game[j][i] << "		";
	cout << endl << endl;
	
	cin.get();
	cin.get();
	return 0;
}

What you need to add:

-A check to make sure that the user input is within the range of 0-20
-Final totals (I didn't know what that was because the numbers didn't add up but I'm guessing that it is for each quarter and finals)
-Do not know if you want to output games that were not inputted. If you do not want to show them make an array (or vector -- I would use) to keep track of the numbers inputted and then output based off that container.

Thank you so much!!
Now it's much more easy for me to complete my hw.
And yes, I just want to display the number of games entered, I will have to keep track of the numbers entered.
Once again, thanks!!!

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.