Comparing 2 char arrays

What my program is supposed to do is generate a random array of characters that is 6 letter. What the user then does is using the letters given try to make words(you can add extra vowels for -1 point each time). So far i have a grip on all of it besides that part of comparing the 2 arrays.
In example if a s r t u i are my random letters in an array
I want ask the user for word... if he/she inputs art as a word, how do i compare the 2 to see if the letters match w/o extra vowels?

Well it's not efficient, but if you displayed your code, I could probably make it so

Furthermore, since this is just a chunk of code, you'd have to set it to where you can redefine the array copy to go through this process 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
char array[6] = {'a', 's', 'r', 't', 'u', 'i'}; // Pretend this was determined randomly
char array2[6] = array; // Copy random array
char word[6]; // Designed for user word
int count = 0;
char temp;

while(true){
    cin >> temp;

    for(int i = 0; i < 6; i++0{
        if(temp == array2[i]){
            // Adds the input letter to the user array, then increments the counter
            word[count++] = temp; 

            array2[i] = '*'; // Sets the used letter to an asterisk (deletes it)

            break;
        }
        else cout << "Letter not available\n" << endl;
    }

    if(count == 6) break; // Made a six-letter word. Need to reset count to 0
    /*
    else if(/*User presses enter/*) break;
    */
}
here is the code i have here

#include <iostream>
using namespace std;
#include <cstring>
#include <cctype>
#include <ctime>
#include <cstdlib>

const int size = 6;

void welcome();
char random_letters(char my_array[]);
char output(char my_array[], char word[]);
char players_words();
bool match_word(int & score, char word[], char my_array[]);



//char input_word();


int main()
{
srand(time(0));
char my_array[8];
char word[10];
int score;

welcome();
random_letters(my_array);
output(my_array, word);
players_words();
match_word(score, word, my_array);
//input_word();

}






void welcome()
{
cout<< endl<< endl<< endl<< endl<< endl <<endl <<endl <<endl;
cout << "Welcome, thank you for choosing to play, in this game you will be provided with"
<< "6 letters. Your goal is to make as many words with the 6 letters. For words 2-3"
<< endl<< " letters you get 2 points, for words 4-5 letters you get 3 points, for words 6 or"
<<" more you get 4 points. You may add vowels not in the list, costing 1 point. To win "
<<"you " << endl <<"need 20 points, you lose if you have a negatie score."
<< endl <<endl <<endl <<endl <<endl <<endl <<endl;
}

char random_letters(char my_array[])
{



for (int i = 0; i <= 5 ; ++i)
{

my_array[i] = (rand() % 26) + 97;
cout << endl;

}
}
char players_words()
{
char word;
cout << "what is your word" << endl;
cin >> word;
cin.get();
return word;
}







//function was to test word & my_array worked
char output(char my_array[], char word[])
{
cout<< my_array;
cout<<'\n';
cout<<word;


}


bool match_word(int & score, char word[], char my_array[])
{ for (int i = 0; i < 10; ++i)
do
{
{ if(word[i] == my_array[i])
{
score=-1;
}

}cin.get(); cout<<score;
} while ((score < 20) && (score > 0));
cin.get();

}




According to a moderator, I can't just go and solve this for you because that is not in the spirit of the forum.

Do you understand what my chunk of code was doing and how to implement into your code?

Are there other issues you are having?
I wouldn't want someone to do it for me haha!! Then i don't learn!

I understood what your program was doing and i tried my best to implement it.... Still not working 100%

This is the checking part

bool found = false; //setting to false to have the condition set it to go
// through the for loop

//this for loop goes through the word[] array
for(int j = 0; j < strlen(word); ++j)
{
bool match = true; //set this to true because the cs tutor said...
//didn't understand why

//this for loop goes through the letters of my_array
// did not finish this section :/ had to go to work so submitting now
for (int i = 0; i < size; ++i)
{
if(my_array[i] != word[j]) // if the condition is met match is false, otherwise match is true
{
match = false;
}
else{
match = true;
}
//sets found to true is match is true
} if(match = true){
found = true;



this is my scoring part

void point_give(int & score, char word[], int word_size){


word_size = strlen(word);
if(word_size == 2 || word_size == 3){
score+=2;
}else if(word_size ==4 || word_size ==5){
score +=3;
}else if(word_size >=6){
score +=4;
}
}
I'm re-writing your post formatted as code so I can look through it easier.
Tip: put
[*code*]
//code here
[*/code*]
at the beginning and end of your copied code without the asterisks to display it as it would in your IDE.

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
//setting to false to have the condition set it to go through the for loop
bool found = false;

//this for loop goes through the word[] array
for(int j = 0; j < strlen(word); ++j){
    //set this to true because the cs tutor said... didn't understand why 
    bool match = true;

    //this for loop goes through the letters of my_array
    // did not finish this section :/ had to go to work so submitting now
    for (int i = 0; i < size; ++i){
        // if the condition is met match is false, otherwise match is true
        if(my_array[i] != word[j]){
            match = false;
        }
        else{
            match = true;
        }
    }
    
    //sets found to true is match is true 
    if(match == true){
        found = true;
    }


//this is my scoring part

void point_give(int & score, char word[], int word_size){
    word_size = strlen(word);

    if(word_size == 2 || word_size == 3){
        score += 2;
    }
    else if(word_size == 4 || word_size == 5){
        score +=3;
    }
    else if(word_size >= 6){
        score +=4;
    }
}
}
Sorry man. I want to help you, but I just can't see what's going on here. I don't really know what you're looking for. But feel free to incorporate that while loop from earlier.

Sorry mate
Topic archived. No new replies allowed.