Word guessing game

Ok so I did this program, but I don't know what the problems are,the computer is supposed to generate a random 4 letter word ( not necessarily meaningful), and you have to input letters and if the letters are in the word it will tell you which one it is, and you should guess te word in the end, ok I'm a beginner and I think there are a lot of problems in it, but could you help me?
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
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <stdlib.h>
         

using namespace std;
int count(char vector[]);
void search(char vector[]);

int main()
{
      char vector [10];
      char option;
      srand (time(NULL));
       for (int i=0; i<4; i++)
       {
        vector[i]= rand() % 26 + 65;
        }
        int A, word[4];
        for (int i=0; i<4; i++)
        {
        word[i]=0;
        }
        for (int j=0 ;j<26;j++)
        {   int letter;
            cout << "Enter a letter in capitals" << endl;
            cin >> letter ;
            if (letter == vector [0])
            word[0]= letter;
            if (letter == vector [1])
            word[1]= letter;
            if (letter == vector [2])
            word[2]=letter;
            if (letter == vector [3])
            word[3]=letter;
            if (word[0]!=0 && word[1]!=0 && word[1]!=0 && word[2}!=0)
            break;    
            }
            for (int k=0;k<4: k++)
            cout << word[k]
            for (int i=0; i<4; i++)
            cout << word[i];
            cout << "Number of efforts:"<< j;
        getch();
        return 0;
}
Line 6: change to #include <cstdlib>
Line 15: Why is your array vector so long, only needs to hold 4 characters.
Line 39: I think you can fix this one...?

I didn't run it, but everything else looks fine.
actually line 39 is my problem, could you help?
I fixed it but It's still not what I'm looking for,

#include <iostream>
#include <conio.h>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <stdlib.h>


using namespace std;
int count(char vector[]);
void search(char vector[]);

int main()
{
char vector [4];
char option;
srand (time(NULL));
for (int i=0; i<4; i++)
{
vector[i]= rand() % 26 + 65;
}
int A, word[4];
for (int i=0; i<4; i++)
{
word[i]=0;
}
for (int j=0; j<26 ;j++)
{
char letter;
cout << "Enter a letter in capitals" << endl;
cin >> letter ;
if (letter == vector [0])
word[0]= letter;
cout << letter;
if (letter == vector [1])
word[1]= letter;
cout << letter;
if (letter == vector [2])
word[2]=letter;
cout << letter;
if (letter == vector [3])
word[3]=letter;
cout << letter;
if ((word[0]!=0) && (word[1]!=0) && (word[2]!=0) && (word[3]!=0))
break;
}
for (int k=0;k<4; k++)
cout << word[k];
for (int i=0; i<4; i++)
{
cout << word[i];
}

getch();
return 0;
}
[/code]
Last edited on
I did it Thanks
No problem. Glad you figured it out.
Topic archived. No new replies allowed.