Keeping Score and Declaring a Winner Assistance

Creating a word game with players and rounds and then at the end it should total up the scores and declare a winner.

Code has been solved. Code listed here is the original code that has not been fixed. Will update code to the final fixed version soon.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

int round_number;
int scores;
int players;
int player_scores;
string input_word;
int player_counter = 0;
int total_points = 0;
int winner = 0;
int win;

int main()
{
	cout << "Welcome to the Word Game!" << endl << endl;

	cout << "How many players will be participating?" << endl;
	cin >> players;

	cout << "\nHow many rounds will be played?" << endl;
	cin >> round_number;
	cin.ignore();

	srand(time(0));

	for (int round_counter = 1; round_counter <= round_number; round_counter++)
	{
		cout << "\nRound: " << round_counter << endl;

		for (int player_counter = 1; player_counter <= players; player_counter++)
		{
			char beginning_letter = (rand() % 26) + 'a';

			cout << "\nPlayer " << player_counter << ": Please enter a word that begins with: " << beginning_letter << endl;
			getline(cin, input_word);

			cout << "Player " << player_counter << " has earned: " << input_word.length() << " points." << endl;

			total_points = input_word.length();
			cout << "\nPlayer " << player_counter << " Points: " << total_points << endl;
		}

	}
	
	cout << "\nThese are the end results!";

	int sum = 0;
	for (int end_score = 0; end_score < total_points; ++end_score)
	{
		sum += total_points;
		end_score = total_points;

		for (int player_counter = 1; player_counter <= players; player_counter++)
		{
			cout << "\nPlayer " << player_counter << " Points: " << end_score << endl;
		}
	}

	cout << "Player " << player_counter << " is the winner!" << endl;
	
	system("PAUSE");
}
Last edited on
Since total_points is for each player you need to turn it into an array. And since it is also per round you need a 2-dimensional array.

For the results you need the same loop as above just swapped. To calculate the sum you need something like this:

Line 43:
total_points[player_counter][round_counter] = input_word.length();

Line 54:
sum += total_points[player_counter][round_counter];
When I try just putting these in to test out, it's saying that I have an error, saying that my expression must have a pointer-to-object type. What exactly is that telling me I need to do to fix that? I can't seem to remember for the life of me.
What exactly is that telling me I need to do to fix that?
I don't know. Show your modified code.

You need to define an array that is at least as large enough to hold the maximum amount, e.g.:

int total_points[100][100] = { 0 }; // 100 player and 100 rounds

You may add code for erroneous user input.
Topic archived. No new replies allowed.