#include <iostream>
using namespace std;
int main()
{
char word[10];
char letter;
char newword[nl];
char wrong[nw];
char correct[nc];
int nl = 0;
int nw = 0;
int nc = 0;
cout << "Enter a word." << endl;
cin >> word;
for(int i = 0; i<10; i++)
if (word[i] != newword[i]
cout << "Guess a letter." << endl;
cin >> letter;
for (int i = nw; i<6; i++)
if (letter != word[10])
return 0;
I am really stuck on this. I making a program to tell the number of letters in an inputted word and keep track of wrong and previously guessed correct letters. Right now I am trying to figure out how to insert letters from one array to another. Like, if a wrong letter is inputted how would I put it into the "wrong" array? Also how would I specify that if it is not any letter in the array, then it is wrong?
You can take a look at this. I basically edited your code to actually work but I did it quickly and didn't document it or test it thoroughly. I also didn't use any functions because it looks like you haven't learned them yet but I used a pointer.
I still don't understand why you would want them to enter a word and then guess it's letters. It's useless since they gave you the actual word. A more clever approach would be to give them a list of words and then randomly choose one for them to guess.
I just worked on it some more. Now I need to figure how to reset match as false every time a letter is guessed.
Oops wrong code. Here's the right one.
#include <iostream>
using namespace std;
int numbletter(char word[], int size);
int main()
{
char input;
bool match=false;
char word[11];
bool right[10];
char alph [27] = "abcdefghijklmnopqrstuvwxyz";
bool wrong [26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int right_guess = 0;
int wrong_guess = 0;
int guesses_left;
int letters_left;
int correct_letters;
guesses_left = 6 - wrong_guess;
letters_left = 0;
cout << "Enter a word." << endl;
cin >> word;
while (wrong_guess<6 && correct_letters<6)
{
cout << "Guess a letter" << endl;
cin >> input;
for (int i=0; i<11; i++)
{
if (input ==word[i]){
correct_letters++;
right[i]=true;
match=true;
}
}
if (match==false)
{
for (int i =0; i<27; i++)
{
if (input == alph[i])
wrong[i] = true;
I would take a look at my sample code and adopt some of the simpler techniques.
Your logic has a lot of flaws. For example the condition:
while (wrong_guess<6 && correct_letters<6)
this is not going to do anything useful because of the statements above it:
1 2 3
int wrong_guess = 0;
int correct_letters;
guesses_left = 6 - wrong_guess;
You are setting guesses_left to 6 so it will not be less than 6 initially and you didn't even initialize correct_letters so the compiler will contain whatever in was in memory last.