samedi 31 mars 2018

Code wont ignore numbers

I am trying to write a simple code but I tried doing a for loop within a if statement but it ended up reversing the numbers and the sentence. I do not know what I am missing or what im doing wrong I commented out the part I was working to get that part to work.

The code is supposed to do this: a FUNCTION which takes in a String as a parameter and returns a Pig Latin version of that string. The program should be able to :

1) handle punctuation

2) Ignore numbers (i.e. if “500” is passed in, “500” is passed back)

3) Handle multiple sentences

  static void Main(string[] args)
    {
        Console.WriteLine("Enter the word or sentence to convert into Pig Latin");
        string sentence = Console.ReadLine();
        string pigLatin = PigLatin(sentence);
        Console.WriteLine(pigLatin);
    }
    static string PigLatin(string sentence)
    {
        string letter = sentence.ToLower();
        string firstLetter, restWord, vowels = "AEIOUaeio";
        //int numbers;
        int current;
        foreach (string word in sentence.Split())
        {
            firstLetter = sentence.Substring(0, 1);
            restWord = sentence.Substring(1, sentence.Length - 1);
            current = vowels.IndexOf(firstLetter);
            if (current == -1)
            {
                sentence = restWord + firstLetter + "ay";

            }
            //for (int numbers = 0; numbers ; numbers++)
            //{
            //   sentence += numbers;
            //}

        }
        return sentence;
    }

Aucun commentaire:

Enregistrer un commentaire