Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying to create a C program function called \"compare_arrays\" in order to

ID: 3771677 • Letter: I

Question

I am trying to create a C program function called "compare_arrays" in order to compare two integer arrays of the same SIZE = 26 (26 because each space represents a character from the alphabet). One array holds a count of how many letters a specific word has. The second array holds the count of letters a user inputs. I am trying to see given the letters entered if I am able to spell that specific word.

I am not sure if I am headed in the right direction.... I am having trouble with the loops..

int compare_arrays(int dictionary[], int user[])
{
   int j; // counter to go through arrays

   for (j = 0; user[j] >= dictionary[j]; j++)
   {
       if (user[j] == '')
       {
           return 1; // you are able to spell the word with the given letters
       }
   }
       else
       {
           return 0; // you are not able to spell the word with the given letters
       }
}

Explanation / Answer

/**
The method compare_arrays that takes two integer arrays
and compares the count of each of arrays at index starting
from 0 to SIZE . Then return 1 if two arrays count is equal
otherwise returns 0.
**/
int compare_arrays(int dictionary[], int user[])
{
   int j; // counter to go through arrays
//Set an integer variable equal that set to 1
   int equal=1;
   //Run for loop that from j=0 to SIZE
   //Set condition j<SIZE && equal evaluates to true
   //only if j less than size and equal to 1
   for (j = 0; j<SIZE && equal; j++)
   {
       //if user given count and dictionary count is not equal
       //Then set equal to zero
       if (user[j] != dictionary[j])
       {
          equal=0;
       }
   }

//Return integer variable equal  
return equal;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote