please could anyone do this program i am a beginner in c# and i need help can u do a program in which the user can enter two words and get the unrepeated letters between two words example computer program
output will be cute please c# syntax. thnx

Hi reemhatim and welcome to DaniWeb :)

There are some pretty strict rules at DaniWeb - we aren't allowed to just do it for you. Have a try yourself and feel free to post questions on specific problems you are having with your algorithm or code and we will try to point you in the right direction.

Good luck :)

reemhatim;

While I'm not about to go ahead and do your code for you I will do what I can to put you in the right direction.

Using the following method you should be able to determine the letters that are not repeated between the two.

  1. Input user selected words as character arrays
  2. Loop all characters in array 1
  3. ForEach character in array 1 check each character in array 2 for equality
  4. if character from array 1 matches 0 characters in array 2 then append to string variable for output
  5. as additional step you can loop all characters in array 2 and compare them to array 1 as well so that you get all characters from 2nd word that don't match first word as well
  6. output string with unmatched characters

Based on your original example "Computer Program" output for option 1 would be "Cute" output for option 2 would be "CutePga"

i know it's a simple program anyone can do it for me. I've tried alot but because I am not familiar with writing programs yet i have asked for help .thanks:)

okay thanks aloot this could help me

I've done the code but there are some mistakes that result in getting incorrect output would you please correct it for me . thank you :)

        string firstWord = Console.ReadLine();
        string secondWord = Console.ReadLine();

        for (int i = 0; i < firstWord.Length; i++)
        {

            int j = 0;
            foreach (char item in firstWord)
            {
                if (firstWord[i] != secondWord[j])
                {
                    Console.Write(item);
                    j++;

                }
                else
                {
                    break;
                }

            }


        }



        for (int i = 0; i < secondWord.Length; i++)
        {

            int j = 0;
            foreach (char item in secondWord)
            {
                if (secondWord[i] != firstWord[j])
                {
                    Console.Write(item);
                    j++;

                }
            }
            else
            {
                break;
            }

        }

I threw this together to illustrate what I was trying to convey with my pseudocode before. Please note that the reason I used .ToLower() on my inputs is to ensure that all characters being compared are in the same case as upper and lower case characters count as different when doing a straight comparison. In order to get the same result with the second compared to first (instead of just first compared to second) simply add another pair of loops with the reverse order for the comparison and you're set.

static void Main(string[] args)
        {
            string unmatched = ""; // Define output string
            string word1 = Console.ReadLine().ToLower(); // Read input of word 1
            string word2 = Console.ReadLine().ToLower(); // Read input of word 2
            char[] word1charArray = word1.ToCharArray(); // Convert word 1 into character array
            char[] word2charArray = word2.ToCharArray(); // Convert word 2 into character array
            bool match = false; // Matched character condition set

            for (int a = 0; a < word1charArray.Length; a++) // Iterate through characters in word 1 array
            {
                for (int b = 0; b < word2charArray.Length; b++) // Iterate through characters in word 2 array
                {
                    if (word1charArray[a] == word2charArray[b]) // Check if current character in word 1 array matches current character in word 2 array and set flag if matched
                    {
                        match = true;
                    }
                }
                if (match != true) // If no match through all characters in word 2 with current character in word 1 add word 1 character to output string
                {
                    unmatched += word1charArray[a].ToString();
                }
                else // If match found reset match flag and start with next character in word 1
                {
                    match = false;
                }
            }
            Console.WriteLine("{0}", unmatched); // Output unmatched characters as string
            Console.Read();
        }

Hope this helps. Also note this is not the ONLY way to do it, just the way *I* would do it.

Please remember to mark the thread solved once your issue is resolved.

thanks aloot for helping :)

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.