Please Need urgent help with my project

just start first year uni , not speak good english now finish project in 2 days , please need help widh this . I need to make c++ programme to do

1st - A function loads a dictionary file of English words into the program .
2nd - The user is asked to enter 8 selections of vowel or consonant in turn, and can see the letters chosen at random at each step
3rd - then search the dictionary for the word or words with longest matching set of letter
4- display word or words

i do little work and wrote this but dont know what next or its right?




#include<fstream>
#include<iostream>
#include<string>
#include"iolib.h"
#include<time.h>
#include<algorithm>
using namespace std;

int main()
{

char input;


ifstream inFile( "C:\\Users\\jo\\Desktop\\FPJ\\Dictionary.txt", ios::in);
if (inFile.is_open())
{
cout << "Dictionary Added Successfully " <<endl ;
inFile.close();
}
else cout << "Unable to open file";


cout << endl << "
Welcome To My Game : "<< endl;

string userinput[8];
for (int i = 0; i < 8; i++)
{

cout << "Enter ONE Consonant or vowel : " << endl;
cin >> userinput[i];
cout << " You entered : " << userinput[i]<< endl;

} ;




Someone please help me width this my head will explode
You should split the reading and writing into functions that way you can see what went wrong and it'll look nicer and more clear.

if you put everything in the main it will be very hard to see where the issue is

Also, if the user is asked to enter 8 selections of vowels or constants, these are all single chars, so there is no use for an array of strings, it will take up unnecessary space

You also don't need include <time>

Your for loop is constructed correctly, but it is good practice to use a function to this and pass the array of chars as reference like:

void enterData( char *&one, int size)

enterData(userinput, 8)

Hi Thank you for reply

should me just use string ? or char? not sure
and program be able to take input and show entered letter when asking for next letter input ?
how?
how to store inputs and then retrieve at once to search dictionary

sorry me clueless about above task.

Just started month ago dont have good grasp on this if you could solve these problem me be really gratefull, I struggle because i transfer from other course and now have homework.

Tried to learn tutorials but too many to read short time
thanks

made changes below , is this better ??

#include<fstream>
#include<iostream>
#include<string>
#include"iolib.h"
#include<algorithm>
using namespace std;

int main()
{
string s1, s2, s3, s4, s5, s6, s7, s8;

ifstream inFile( "C:\\Users\\Jack\\Desktop\\FPJ\\Dictionary.txt", ios::in);
if (inFile.is_open())
{
cout << "Dictionary Added Successfully " <<endl ;
inFile.close();
}
else cout << "Unable to open file";


cout << endl << " Welcome To My Game : "<< endl;




cout << "Enter a consonant or vowel : ";
while (getline(cin, s1) && s1.size() != 1)
{

cout << "Please Enter A Valid Value ";
}

cout << "You have entered " << s1 << endl;




cout << "Enter a consonant or vowel : ";
while (getline(cin, s2) && s2.size() != 1)
{

cout << "Please Enter A Valid Value ";
}

cout << "You have entered " << s2 << endl;



cout << "Enter a consonant or vowel : ";
while (getline(cin, s3) && s3.size() != 1)
{

cout << "Please Enter A Valid Value ";
}

cout << "You have entered " << s3 << endl;

cout << "Enter a consonant or vowel : ";
while (getline(cin, s4) && s4.size() != 1)
{

cout << "Please Enter A Valid Value ";
}

cout << "You have entered " << s4 << endl;

cout << "Enter a consonant or vowel : ";
while (getline(cin, s5) && s5.size() != 1)
{

cout << "Please Enter A Valid Value ";
}

cout << "You have entered " << s5 << endl;





cout << "Enter a consonant or vowel : ";
while (getline(cin, s6) && s6.size() != 1)
{

cout << "Please Enter A Valid Value ";
}

cout << "You have entered " << s6 << endl;


cout << "Enter a consonant or vowel : ";
while (getline(cin, s7) && s7.size() != 1)
{

cout << "Please Enter A Valid Value ";
}

cout << "You have entered " << s7 << endl;

cout << "Enter a consonant or vowel : ";
while (getline(cin, s8) && s8.size() != 1)
{

cout << "Please Enter A Valid Value ";
}

cout << "You have entered " << s8 << endl;


cout << " You Entered : " << s1 << s2 << s3 << s4 << s5 << s6 << s7 << s8 << endl;







return 0

now need to store these values and then search dictionary for longest words?no clue
thanks
Last edited on

What is a constant? What is a vowel? Is it a single character or a "string" of characters?...

If you are loading a file into the program, the file has to be put somewhere, you can't just open the file and close it, this will not do anything

Last edited on
It looks like you are closing the file right after you see if it's open.

You want to close it when the program is done reading the file.
Hi thanks for help finally managed to get it all working , except for one problem
I am using arrays to save user input of a total of eight letter . The program asks for them one by one example


Enter a random vowel or consonant: u
You have entered: u

Enter a random vowel or consonant: run
You have entered: ur

Enter a random vowel or consonant: You have entered: uru

Enter a random vowel or consonant: You have entered: urun

-----------

as you can see above its allowing entry of more than one letter, i want to restrict to one letter input only



Your using string, so it allows any number of characters.

If you only want to use the first char, you can use string.size to check the length and string erase to erase all but the 1st char.

http://www.cplusplus.com/reference/string/string/erase/

Topic archived. No new replies allowed.