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

  • SEARCH
  • Home
  • 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 6684831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:59:08+00:00 2026-05-26T04:59:08+00:00

I’ve had quite a bit of experience with programming (three semesters teaching VBasic, C++,

  • 0

I’ve had quite a bit of experience with programming (three semesters teaching VBasic, C++, and Java), and now I’m in college and I’m taking a C# class, which is quite boring (the teacher knows less than I do).

Anyways, for one of our exercises, we’re creating a number guessing/lottery game. It works kind of like this:

  • User inputs three integers from 1-4 and clicks submit (I have them storing into an array)
  • Program generates three numbers from 1-4 (also in an array)
  • Function that checks matching runs and checks the two arrays
    • If all three match in order (i.e. 1,2,3 = 1,2,3 and NOT 1,2,3 = 1,3,2), matching = 4
    • If all three match NOT in order, matching = 3
    • If only two match, matching = 2
      • I want to make sure that only one match counts as one (i.e. [1,1,2][1,2,3] only gives one match to the user.
    • If only one matches, matching = 1
    • If no matches, matching stays at 0 (it’s instantiated at submit_click)

I’ve got all of the code and GUI working except for the matching logic. I know I could do it with a LARGE amount of if statements, and I know cases would probably work, but I’m not as experienced with cases.

I’m not expecting my ‘homework’ to be done here, but I just want to know what method would be most effective to get this to correctly work (if it’s easier to exclude the one match per item, then that’s fine), and to possibly see some working code.

Thanks!

EDIT

I apologize if I come across as arrogant, I didn’t mean to come across as a know-it-all (I definitely do not).

I have NOT taught classes, I’ve just taken classes from a teacher who’s primarily a programming in and I’m at a community college and my professor isn’t primarily a programming teacher.

I didn’t take time to write a ton of if statements because I know that it would just get shot down as ineffective. I currently don’t have the resources to test the answers, but as soon as I can I’ll check them out and post back.

Again, I apologize for coming across as rude and arrogant, and I appreciate your answers more than you know.

Thanks again!

  • 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-05-26T04:59:09+00:00Added an answer on May 26, 2026 at 4:59 am

    You can use a loop to achieve this functionality. I’ve used a list simply for ease of use, performing remove operations and the like. Something like this should work:

    public static int getNumberOfMatches(List<int> userGuesses, List<int> machineGuesses) {
        // Determine list equality.
        bool matchedAll = true;
        for (int i = 0; i < userGuesses.Count; i++) {
            if (userGuesses[i] != machineGuesses[i]) {
                matchedAll = false;
                break;
            }
        }
    
        // The lists were equal; return numberOfGuesses + 1 [which equals 4 in this case].
        if (matchedAll) {
            return userGuesses.Count + 1;
        }
    
        // Remove all matches from machineGuesses.
        foreach (int userGuess in userGuesses) {
            if (machineGuesses.Contains(userGuess)) {
                machineGuesses.Remove(userGuess);
            }
        }
    
        // Determine number of matches made.
        return userGuesses.Count - machineGuesses.Count;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I used javascript for loading a picture on my website depending on which small
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.