Inputting a string into a array using cin and getline

This is Word Jumble program for a class. I was told I need to allow the user to input what word and hint they would like and store it into the array. I am having trouble doing so and have no idea where to start. I know I need to use cin to get the word, and getline to use the hint.

In my code, I left some stuff over from when I was trying it out, obviously I have no idea what I'm doing. The code is also shortened, because I think the rest is irrelevant.

All help is appreciated!

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

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	char playAgain;
	string addedWord, addedHint;
	int score = 10;
    enum fields {WORD, HINT, NUM_FIELDS};
    const int NUM_WORDS = 6;
    const string WORDS[NUM_WORDS][NUM_FIELDS] = //First is the word, second is the hint
    {
        {"wall", "Do you feel you're banging your head against something?"},
        {"glasses", "These might help you see the answer."},
        {"labored", "Going slowly, is it?"},
        {"persistent", "Keep at it."},
        {"jumble", "It's what the game is all about."},
		//{addedWord,addedHint}
    };

	do{ //Do loop for playing it again

  	srand(time(0));
	int choice = (rand() % NUM_WORDS);
    string theWord = WORDS[choice][WORD];  // word to guess
    string theHint = WORDS[choice][HINT];  // hint for word

    string jumble = theWord;  // jumbled version of word
    int length = jumble.size();
    for (int i=0; i<length; ++i)
    {
        int index1 = (rand() % length);
        int index2 = (rand() % length);
        char temp = jumble[index1];
        jumble[index1] = jumble[index2];
        jumble[index2] = temp;
    }

    cout << "\t\t\tWelcome to Word Jumble!\n\n";
    cout << "Unscramble the letters to make a word.\n";
    cout << "Enter 'hint' for a hint.\n";
	cout << "You start with 10 points, you lose 1 for each incorrect guess.\n";
	cout << "You lose 3 points for using a hint.\n\n";

	/*cout << "Add a word and a hint to be added.\n";
	cout << "Word: ";
	cin >> addedWord;
	cout << "Hint: ";
	cin.ignore(); // Needed to have getline not skip
	getline(cin, addedHint); */
All I needed to do was change where I asked the user to input the word and hint. I feel foolish now :D
Topic archived. No new replies allowed.