I am trying to set up a a program that gets four numbers from the user, also a random generator to get four numbers compare if any were the same and print out how many numbers were matching this is what I have so far...

using System;

class Program
{



    static void Main(string[] args)
    {
        Console.Title = "Simple RNG";

        int ran1;
        int ran2;
        int ran3;
        int ran4;

        Console.WriteLine("Please enter first random numberfrom 1 - 10");
        ran1 = Convert.ToInt32(Console.ReadLine());


        Console.WriteLine("Please enter second random numberfrom 1 - 10");
        ran2 = Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("Please enter third random numberfrom 1 - 10");
        ran3 = Convert.ToInt32(Console.ReadLine());

        Console.WriteLine("Please enter fourth random numberfrom 1 - 10");
        ran4 = Convert.ToInt32(Console.ReadLine());

        Random randomNum = new Random();

        int myRandom1;
        int myRandom2;
        int myRandom3;
        int myRandom4;

        myRandom1 = randomNum.Next(1, 10);
        myRandom2 = randomNum.Next(1, 10);
        myRandom3 = randomNum.Next(1, 10);
        myRandom4 = randomNum.Next(1, 10);

        Console.WriteLine("\n\nYour random numbers are: {0} {1} {2} {3}", myRandom1, myRandom2, myRandom3, myRandom4);


        Console.WriteLine("The four numbers you entered are: {0} {1} {2} {3}" , ran1, ran2, ran3, ran4);



    }
}

For ease of checking for matches, place your user's guesses in an integer array (you can do it for the randoms to if you want) then use the array's Contains method to see if there is a match.

int[] array = new int[4] {ran1, ran2,ran3, ran4};
int[] guesses = new int[4] {guess1,guess2,guess3,guess4};
int score = 0;
for(int i =0; i < array.Length; i++) {
   if(array.Contains(guesses[i]) {
      score++;
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.