Word Challenge game, need help.

I am working on a Word Challenge program and I am having some trouble understanding and getting arrays to work correctly.

I do not expect a full range answer, but I would like some help anywhere/anyway I can get it.

I need the program to be able to store the players scores into an array.
I need to be able to output the total score for each player at the end of the game, in the order of highest to lowest (first place, second place, etc.)

Please bare with my newbie style of coding, I've only been at this a few months (much less time spend actually coding) and I'm still trying to get used to how everything works.

Also, might be pushing my luck here, but I am also trying to make sure that the player enters a word that starts with the random letter given each round, and of course, check a word bank text file to make sure it is an actual word. I already have a wordlist.txt (from Scrabble dictionary.)

This is what I have done so far.
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <float.h>
#include <fstream>
#include <unordered_set>
#include <hash_set>
#include <allocators>
#include <algorithm>
#include <cstdlib>
#include <ctime>
//Sort of went overboard here; Prototype preparation you could say, in case something is needed
//Should be cleaned up before turning in

using namespace std;

//Global declarations
static const char randomizedLetter[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int stringLength = sizeof(randomizedLetter)-1;
int players, rounds;
int wordPoints(string playerWord);
int playerScores[50][4];
void intro();
string random;

char randomLetter() //Function for randomized letter
{
	return randomizedLetter[rand() % stringLength];
}

int main()
{
	//Some local declarations
	int wordValue = 0;
	string playerWord;
	srand(time(0)); //Not sure if this is needed

	intro();
	cout << "Please enter the number of players (Max 4): ";
	cin >> players;
	cout << "\nPlease enter the number of rounds (Max 50): ";
	cin >> rounds;

	vector< int > amountPlayers(players);
	vector< int > amountRounds(rounds);

	cout << "\n\n" << amountPlayers.size() << " players.";
	cout << "\n" << amountRounds.size() << " rounds.";

	for (int roundCounter = 0; roundCounter < rounds; roundCounter++) //Loop for rounds
	{
		cout << "\n\nRound " << roundCounter + 1 << endl;
		
		random = randomLetter();
		
		cout << "\nThe round random letter is: " << random << endl;

		for (int playerCounter = 0; playerCounter < players; playerCounter++) //Loop for players
		{
			cout << "\nPlayer " << playerCounter + 1 << " please enter your word: ";
			cin >> playerWord;

			wordValue = wordPoints(playerWord);

			cout << "\nYour word '" << playerWord << "' is worth: " << wordValue << " points.\n";

			//should store 'wordValue' in an array
		}
	}
        //Post End of Game data; Total Scores and the Winner.

	system("PAUSE");
	return 0;
}

void intro() //Output introduction text
{
	cout << "Welcome to the Word Challenge Game!\n";
	cout << "Who can come up with the most valuable word when given a random first letter?!\n";
	cout << "Test your literary skills!\n\n";
}

int wordPoints(string playerWord) //Function to assign points to the players word
{
	size_t j = 0, Value = 0;
	for (j = 0; j < playerWord.size(); j++)
	{
		if (playerWord[j] == 'a' || playerWord[j] == 'A' || playerWord[j] == 'e' || playerWord[j] == 'E' || playerWord[j] == 'i' || playerWord[j] == 'I' ||
			playerWord[j] == 'o' || playerWord[j] == 'O' || playerWord[j] == 'n' || playerWord[j] == 'N' || playerWord[j] == 'r' || playerWord[j] == 'R' ||
			playerWord[j] == 't' || playerWord[j] == 'T' || playerWord[j] == 'l' || playerWord[j] == 'L' || playerWord[j] == 's' || playerWord[j] == 'S' ||
			playerWord[j] == 'u' || playerWord[j] == 'U')
			Value += 1;
		else if (playerWord[j] == 'd' || playerWord[j] == 'D' || playerWord[j] == 'g' || playerWord[j] == 'G')
			Value += 2;
		else if (playerWord[j] == 'b' || playerWord[j] == 'B' || playerWord[j] == 'c' || playerWord[j] == 'C' || playerWord[j] == 'm' || playerWord[j] == 'M' ||
			playerWord[j] == 'p' || playerWord[j] == 'P')
			Value += 3;
		else if (playerWord[j] == 'f' || playerWord[j] == 'F' || playerWord[j] == 'h' || playerWord[j] == 'H' || playerWord[j] == 'v' || playerWord[j] == 'V' ||
			playerWord[j] == 'w' || playerWord[j] == 'W' || playerWord[j] == 'y' || playerWord[j] == 'Y')
			Value += 4;
		else if (playerWord[j] == 'k' || playerWord[j] == 'K')
			Value += 5;
		else if (playerWord[j] == 'x' || playerWord[j] == 'X' || playerWord[j] == 'j' || playerWord[j] == 'J')
			Value += 8;
		else if (playerWord[j] == 'q' || playerWord[j] == 'Q' || playerWord[j] == 'z' || playerWord[j] == 'Z')
			Value += 10;
	}
	return Value;
}

Last edited on
Well, I have figured out the part I was having so much trouble with.
I went with using a vector:

1
2
	vector< vector<int> > playersRounds; //Initializes the vector that holds the score
	playersRounds.resize(rounds, vector<int>(players, vectorInitValue)); //Resizes the vector to match rounds and players entered by user 


 
			playersRounds[roundCounter][playerCounter] = wordValue; //Adds the value of the word into the Vector for the round and player 


1
2
3
4
5
6
7
8
9
10
11
12
	cout << "\n\nEnd of Game Scores are as follows:\n" << endl;;
	cout << "       ";
	for (int p = 0; p < players; ++p)
		cout << " 'Player " << p + 1 <<"'";
	cout << endl;
	for (int r = 0; r < rounds; ++r)
	{
		cout << "Round" << r + 1;
		for (int rp = 0; rp < players; ++rp)
			cout << setw(8) << playersRounds[r][rp] << " ";
		cout << endl;
	}
Topic archived. No new replies allowed.