Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8645329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:31:26+00:00 2026-06-12T12:31:26+00:00

Hello I’m working on a quick program that generates a master code and the

  • 0

Hello I’m working on a quick program that generates a master code and the user has to guess the code. When checking the user’s guess I use 2 functions one for Exact Matches and the other for close matches (where they got a number that’s in the mastercode but not in the right location)

Ex. master code 1 2 3 4

user 2 3 2 4
the output the should show the user has 2 close matches and one exact match. I’m having trouble understanding how to properly return an int.

My ouput just shows the default value of exactMatch and closeMatch when I try to print them in Main. any insight will be greatly appreciated. Thank you.

 #include<stdio.h>
 #include<math.h>
 #include<stdlib.h>
 #include<time.h>
 #define CODELENGTH 4
 #define NUMSYMBOLS 6


 int MasterCode[4];
 int guess[ 4 ];
 int exactMatch;
 int closeMatch=0;

 void genCode (int MasterCode[])
{
int i=0;
int k;
while (i < CODELENGTH){

MasterCode[i] =rand() %NUMSYMBOLS +1;
    i++;

}//end while loop.
for ( k = 0 ; k < 4; k++ ) {
    printf( "%d ", MasterCode[ k ] );
}

printf( "\n" );
}





 void getGuess (int guess[])
{

int number = 0;

printf( "Please enter your list of 4 numbers between 1 and 6: " );
int j;
int k;
for ( j = 0 ; j < 4; j++ ) {
    scanf( "%d", &number );
    guess[ j ] = number;
}

printf( "Your array has these values: " );

for ( k = 0 ; k < 4; k++ ) {
    printf( "%d ", guess[ k ] );
}

printf( "\n" );
 }




 int main (int argc, char **argv)
 {
srand ( time(NULL) );

genCode(MasterCode);
getGuess(guess);
checkExactMatches(MasterCode, guess, exactMatch);
checkCloseMatches(MasterCode, guess, closeMatch);
printf("%d = Ending exactMatches \n", exactMatch);
printf("%d  = Ending closeMatches \n", closeMatch);





 }
 int checkExactMatches (int MasterCode[], int guess[], int exactMatch )
  {
int woot;
for(woot=0; woot<4; woot++){


        if (MasterCode[woot] == guess[woot]){
            printf("Exact Match found \n");
            exactMatch ++;
            printf( "%d = Guess \n" , guess[ woot ]);
            printf( "%d = MasterCode \n", MasterCode[ woot ]);
            printf("%d = exactMatch \n", exactMatch);

        }// end if

        if (MasterCode[woot] != guess[woot])
            printf("No EXACT match \n");


}//end for loop

return exactMatch;
 } // end checkExactMatches



 int checkCloseMatches (int MasterCode[], int guess[], int closeMatch )
  {
int k;
int j;
for(k=0; k<4; k++){

    for (j=0; j<4; j++) {


        if (MasterCode[k] == guess[j]){
    printf("CLOSE Match found \n");
    closeMatch ++;
    printf( "%d = Guess \n" , guess[ j ]);
    printf( "%d = MasterCode \n \n", MasterCode[ k ]);
    printf("%d = closeMatch \n \n", closeMatch);

}// end if

if (MasterCode[k] != guess[j])
    printf("No CLOSE match \n");


    }//end nested for loop
}//end for loop

return closeMatch;
 } // end checkCloseMatches
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:31:27+00:00Added an answer on June 12, 2026 at 12:31 pm

    Getting the value returned from a function is actually really easy, it’s basically the same as assigning a value to a variable. In your case, the syntax would be something like this:

    int result = checkExactMatches(MasterCode, guess, exactMatch);
    

    result will now hold the value returned by the function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello I am working with a simulator that uses rcS scripts to boot, this
Hello I am trying to use TCL in a program called Shorthand which is
Hello all I am working on javascript jquery and svg.I want to ask a
Hello all I am working on html and javascript.And I am going to ask
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
hello all i am working on a project in which i have a webpage
Hello i have this code var queue = new BlockingCollection<int>(); queue.Add(0); var producers =
Hello I have a multigeometry How has a Style like a rollover when you
Hello I want to know how to highlight all Words that is inputted in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.