1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hi Guest, welcome to the TES Community!

    Connect with like-minded education professionals and have your say on the issues that matter to you.

    Don't forget to look at the how to guide.

    Dismiss Notice

help with c# code

Discussion in 'Computing and ICT' started by Sherbear320, Nov 8, 2018.

  1. Sherbear320

    Sherbear320 New commenter

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace PigLatin
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    string phrase;
    string decide;
    char first;
    List<string> phraseWords = new List<string>();
    List<string> pigLatin = new List<string>();

    private void translation(object sender, EventArgs e)
    {
    phrase = txtPhrase.Text;

    //split typed phras where there is a space and add to list Phrasewords
    phraseWords = phrase.Split(' ').ToList();
    //go through each word in the phraseword list and check if it begins with a vowel or not
    for (int i = 0; i < phraseWords.Count; i++)

    //store word from list in string called decide
    decide = phraseWords;
    //get first character from decide
    first = decide.First();

    {
    //check if the word begins with a vowel
    if ((first == 'a') || (first == 'e') || (first == 'i') || (first == 'o') || (first == 'u'))
    {
    //if first letter is a vowel call function vowelchanger
    vowelChange();
    }

    else
    {
    //if first letter constanence call function constance changer
    constananceChange();
    }
    }


    }
    // add yay to the end
    void vowelChange()
    {
    MessageBox.Show(decide);
    decide += "yay";
    // MessageBox.Show(decide);
    txtTranslation.Text += decide;
    }
    void constananceChange()
    {
    decide = decide.Substring(1);
    decide += first;
    MessageBox.Show(decide);

    bool flag = true;
    //Keep moving through the word moving constanance to the end until you reach a vowel and then add ay
    while (flag)
    {
    first = decide.First();
    if ((first == 'a') || (first == 'e') || (first == 'i') || (first == 'o') || (first == 'u'))
    {
    //MessageBox.Show("I found a vowel " + first);
    decide += "ay";
    flag= false;
    //MessageBox.Show(decide);
    }

    else
    {
    //MessageBox.Show("I found a constanance " + first);
    decide = decide.Substring(1);
    decide += first;
    txtTranslation.Text += decide;
    //MessageBox.Show(decide);
    }
    }
    }
    }
    }


    Hi

    Trying to devise a little exercise where kids type in phrases into a text box and then the phrase is fed into a list word by word.

    It should then examine each word and change it to pig Latin.

    The code works for one word, but not multiple word phrases. In this case it only translates the last word.

    Please can you help, I am so not a programmer!!

    She
     
  2. moscowbore

    moscowbore Senior commenter

    "Please can you help, I am so not a programmer!!"

    So why are you trying to teach it?

    You do know that words are made up of vowels and consonants don't you?

    Why not just read the whole line into a string and then search through the string using spaces as word delimiters?
     
  3. Sherbear320

    Sherbear320 New commenter


    Wow such a nice person!!!

    Well if you read the code the string is read in and delinineated using the spaces into an array.

    There is a mistake in the top bracket placement in the for loop.

    I didn’t ask for critique on my spelling thanks. I would always check before giving to a student.

    If you are so upset with the world that you have to be horrible I feel for you.
     
  4. moscowbore

    moscowbore Senior commenter

    If someone asked me to teach Mandarin, I would refuse as I know nothing about Mandarin. I would be doing students a disservice by trying to teach Mandarin as I would be very bad at it.

    I have been a computing teacher for many years. I know how to teach programming. It would be entirely appropriate for me to be asked to teach the task you mentioned as I would break the task down into a design before attempting to churn out code.

    It seems to be acceptable that someone who knows nothing about programming/computing be asked to teach it.

    Thus computing as a subject is all but dead.
     
  5. Thanks for the information.
     

Share This Page