Click here to Skip to main content
16,004,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i`m new to the this website and this is my first time asking a question.

Here`s my problem i have this question

: Ask the user for two words and then print does words in ascending order ?

Here is what i have done so far:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ascending_Order_Example
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter a random word of your choice : ");
            string letter1 = Console.ReadLine();

            Console.WriteLine("Please enter another word of your choice : ");
            string letter2 = Console.ReadLine();

        }
    }
}


I don`t know how to print the words givin in ascending order?
Can anyone please help me
Thank you.
Posted
Updated 3-Aug-20 3:01am
Comments
ZurdoDev 4-Apr-13 8:27am    
This would appear to be homework. What have you done so far? Have you researched sorting algorithms?

I would suggest this link:

C# String Sort Algorythm Search[^]


There are various solutions to your problem there. The top link looks promising!
 
Share this answer
 
Just use the String.Compare[^] method.
 
Share this answer
 
Use the Array.Sort[^] method to sort the words, and then use a foreach loop[^] to print them in ascending order:
C#
Console.WriteLine("Please enter a random word of your choice : ");
string letter1 = Console.ReadLine();
 
Console.WriteLine("Please enter another word of your choice : ");
string letter2 = Console.ReadLine();

string[] words = new string[] { letter1, letter2 }; // create the array
Array.Sort(words);
foreach (string word in words)
{
     Console.WriteLine(word);
}

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900