Ok, here\'s a tough one. In C++, I\'ve been working on a program that will allow
ID: 639100 • Letter: O
Question
Ok, here's a tough one.
In C++, I've been working on a program that will allow the user to enter AT MOST ten letters and AT LEAST three letters (if the user wishes to enter less than ten, they may enter a "-" to end the input process). These will be entered into an array. Then the program will use another function to read a TXT file (and probably read the file into another array). The program will then compare the letters that the user entered into the previous array with the TXT file array(which holds a long list of three-letter-words). If the entered letters can be combined to make any of the words on the TXT list, then the program will output those words. I know that I'm supposed to use pointers to go back and forth between functions, but I'm now at a point where I'm STUCK! Please help!
Here's what I've got so far....
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void processUserInput(char *letters[])
int main()
{
cout<<"...START..."<<endl;
menu();
system ("PAUSE");
return 0;
}
void processUserInput(char *letters[]);
void findWords();
void menu();
void readLegalWords();
{
//This function reads and prints the word combinations found by the first two functions listed below
cout<<"Enter between 3 and 10 lowercase letters"<<endl;
cout<<"Enter a '-' to stop reading letters if there are less than 10"<<endl;
for (int input=0;input<10;input++)
{
if (*letters[input]="-")
{
return;
}
else
{
cin>>*letters[input];
}
}
{
cout<<"These are the letters you input: "<<endl;
cout << letters[input] << endl;
findWords();//the next function is called here
}
void findWords()//this function will find the words
{
char *letters[10];
readLegalWords();
}
void readLegalWords()//this function will read in from the TXT file, putting it into a new array
{
ifstream inputFile;
inputFile.open("words.txt");
}
void menu()//this is our main menu that's listed
{
char selection;
cout<<"Enter your choice:"<<endl;
cout<<"(F)ind words"<<endl;
cout<<"or"<<endl;
cout<<"(Q)uit"<<endl;
cout<<"CHOICE: "<<endl;
cin>>selection;
switch(selection)
{
case 'f':
case 'F':processUserInput();
break;
case 'q':
case 'Q':cout<<"Game over."<<endl;
system("PAUSE");
return 0;
default: cout<<"Invalid Entry. Try again."<<endl;
}
}
Explanation / Answer
#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
}
}
your code plee see
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.