Three letter game

Hello, beginner programming student here. Had a year long break due to deployment and became very rusty. Really disheartening as I thought my skills were improving. having a difficult time with current task at hand. If it were not for time parameters and other competing priorities (like we all have) pretty sure I'd be able to solve the algorithm. Please look over my code and let me know if I'm on the right path. Hints are also appreciated. I very much want to learn and understand but again a year off to a beginner is tough. Thanks for your help in advance as I'm probably going to seek it again.

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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  /* This program is called the Three Letter Words (TLW)
program. The program will do the following.


1. Screen output "Welcome to TLW Game."
2. Call to menu function prompting user to continue or 
Quit the program.
3. If player continues menu function will call another 
function to process user input processUserInput();
**This function will prompt player to enter 3-10 lowercase
letters**
**if player doesn't enter 3-10 a error message is displayed
**Enter a - (dash) to stop reading letters. This part I do not understand
**if the - is entered input will stop and the program should move on and
output the letters entered back to the player on the screen
4. After letters are entered the processUserInput() function will call
another function called findWords() function and fill an array with legal three 
letter words and print them to screen if more than 1 word can be made
**this function should call findWords() function and do the following
Read data from file words.txt and the array of letters read from player
and return an array of unique 3 letter words that can be made from the 
letters
5. A final function that is called only once readLegalWords() function
will read contents of words.txt into an array of strings. Max number of words
in array is 2000 (should i set the array for 2000 elements??)
screen*/

#include <iostream>
#include <iomanip> //not sure this is needed but include just in case
#include <string> //need this for string class
#include <fstream>//must have this to work with files

using namespace std;

//Declare Functions before the main??
char menu(); //function prototype for menu function
void processUserInput(); //function prototype for user input function



int main()
{
	cout<<"Welcome to Jellos TLW Game"<<endl;
	char menuChoice = ' '; //variable to hold user's choice

	//Call to menu function
	menu();



system ("Pause");
return 0;
}

//Begin Function definitions
//Start with menu function to prompt game player

char menu()
{
	char menuChoice = ' '; //variable to hold choice
	cout<<"Enter your Choice: "<<endl;
	cout<<"    (F)ind Words"<<endl;
	cout<<"    (Q)uit"<<endl;
	cin>>menuChoice;

		if(menuChoice == 'F' || menuChoice == 'f')
		{
			/*call to function that will ask user to enter
			between 3-10 letters*/
			processUserInput();
						
		}
		else if(menuChoice == 'Q' || menuChoice == 'q')
		{
			cout<<"Thanks for playing Jellos TLW Game!"<<endl;
			return 0;
		}
} //end of menu function

/*This function should read the input letters into a string array?? */

void processUserInput(); 
{
	//Declare variables and arrays
	string inputLetters[]; //array to hold the player input	
	int letterCount; //variable to input quantity
	//Print to screen
	cout<<"Enter up to 10 lowercase letters."<<endl;
	cout<<"You must enter at least 3 letters."<<endl;
	cout<<"Enter a '-' to stop reading letters if you want less than 10."<<endl;

	cin>>inputLetters; //accept user input

	/* Test the following conditions are met
	** at least 3 letters are entered
	** no more than 10 letters are entered
	** so long as 3 letters are entered a - will stop input
	** all input is lowercase letter or - anything else will display error message
	
	** once input is entered correctly the letters the player entered are displayed
	back to him/her on a single line
	
	** correct data will call to function findWords() which will fill an array with 
	legal 3 letter words from player input and print the words if there are more than 1 

	** findWords() will most likely have to compare string arrays (player input vs file that 
	is read from another function */

	
	
	//Need to test three conditions
	//If player entered 3-10 letters
	//If player entered lowercase letters
	//do not know how to test whether player entered lower case letters

	if(inputLetters >= 3 || inputLetters <= 10 && //test for lowercase)
	{
		//call to function proccessUserInput();
	}

	else if(inputLetters < 3 || inputLetters > 10 && inputLetters //is not lowercase??)
	{
		//display error message
		cout<<"You must enter 3-10 lowercase letters "<<endl;
		cout<<"Enter a '-' to stop reading letters if you want less than 10. "<<endl;
		//need code that stops input if user enters a '-' (dash)
		//display error code if not lower case or less than 3
		
	}
}

Just picking up on your comments in the code....

//not sure this is needed but include just in case
then comment it out. does the code still compile?

//Declare Functions before the main??
Yes, forward declarations are good :) try doing it without them ;)

do not know how to test whether player entered lower case letters
islower(c);
You cant check the entire string in one go, you have to do it letter by letter.

if(inputLetters >= 3 || inputLetters <= 10 && //test for lowercase)
I think your letters really need to be >=3 AND <= 10

How does main() know if processUserInput() was successful?


processUserInput lets the user enter text only once, the entire string in one hit. how do you see "-" to exit working?



else if(inputLetters < 3 || inputLetters > 10 && inputLetters //is not lowercase??)
just the else would do here if (true) else if (false) isn't really necessary.

[edit]
Your use of string for inputLetters is poor. firstly you declare an array of strings [], and your "if statement" should look more like
if (inputLetters.length() >= 3 && inputLetters.length() <= 10

but your compiler could have told you that.

Last edited on
Topic archived. No new replies allowed.