none
Is there a way to loop back to the top of a code segment? (This is a very bad explanation) RRS feed

  • Question

  • So I am working on my current exercise in my class and the objective is as follows:

    "Three salespeople work at Sunshine Hot Tubs—Andrea, Brittany, and Eric. Write a console-based application that prompts the user for a salesperson’s initial (‘A’, ‘B’, or ‘E’). While the user does not type ‘Z’, continue by prompting for the amount of a sale the salesperson made. Calculate the salesperson’s commission as 10% of the sale amount, and add the commission to a running total for that salesperson. After the user types ‘Z’ for an initial, display each salesperson’s total commission earned. Save the file as TubSales.cs."

    Now I know that I can cheat and literally copy and paste that online and get the answer, but I want to become a programmer in the future for a career so I am actually trying to make this work by myself.
    Anyways here is what I have so far:

    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Dim and start
                double saleA = 0, saleB = 0, saleE = 0, commissionA = 0, totalA = 0, commissionB = 0, totalB = 0, commissionE = 0, totalE = 0;
                int done = 0, logoff = 0;
                Console.WriteLine("Give me your initial.....");
    
                // Initial Check
                string initial = Console.ReadLine();
                while (initial != "A" && initial != "B" && initial != "E")
                {
                    Console.WriteLine("YOU'RE NOT DAVE!!!");
                    initial = Console.ReadLine();
                }
    
                // Hello Initial
                if (initial == "A")
                    Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "B")
                    Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "E")
                    Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
    
    
                // Calculate initial "A"'s values
                while (logoff == 0)
                {
                    do
                    {
                        do
                        {
                            saleA += Convert.ToDouble(Console.ReadLine());
                            commissionA = saleA * .10;
                            totalA = commissionA + saleA;
                            Console.WriteLine("Enter \"Z\" if you are finished, continue?");
                        } while (Console.ReadLine() != "Z" && initial == "A");
    
                        Console.WriteLine("Current Sales are: {0}", saleA);
                        done = 1;
                    } while (initial == "A" && done == 0);
    
                    logoff = 1;
                }
                
    
                // RESET VALUES
                done = 0;
                Console.WriteLine("Give me your initial.....");
    
                // Initial Check
                initial = Console.ReadLine();
                while (initial != "A" && initial != "B" && initial != "E")
                {
                    Console.WriteLine("YOU'RE NOT DAVE!!!");
                    initial = Console.ReadLine();
                }
    
                // Initial hello
                if (initial == "A")
                    Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "B")
                    Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "E")
                    Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
                // Calculate initial "B"'s values
                while (Console.ReadLine() != "Z" && initial == "B")
                {
                    saleB += Convert.ToDouble(Console.ReadLine());
                    commissionB = saleB * .10;
                    totalB = commissionB + saleB;
                    Console.ReadLine();
                }
    
                // Initial Check
                initial = Console.ReadLine();
                while (initial != "A" && initial != "B" && initial != "E")
                {
                    Console.WriteLine("YOU'RE NOT DAVE!!!");
                    initial = Console.ReadLine();
                }
    
                // Inital hello
                if (initial == "A")
                    Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "B")
                    Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "E")
                    Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
                // Calculate initial "E"'s values
                while (Console.ReadLine() != "Z" && initial == "E")
                {
                    saleE += Convert.ToDouble(Console.ReadLine());
                    commissionE = saleE * .10;
                    totalE = commissionE + saleE;
                    Console.ReadLine();
                }
    
                // Spacer
                Console.WriteLine();
    
                // Andrea stats
                Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine + 
                    "sale of: " + saleA.ToString("C2") + Environment.NewLine + 
                    "commission of: " + commissionA.ToString("C2") + Environment.NewLine +
                    "total of: " + totalA.ToString("C2"));
    
                // Brittany stats
                Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                    "sale of: " + saleB.ToString("C2") + Environment.NewLine +
                    "commission of: " + commissionB.ToString("C2") + Environment.NewLine +
                    "total of: " + totalB.ToString("C2"));
    
                // Eric stats
                Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                    "sale of: " + saleE.ToString("C2") + Environment.NewLine +
                    "commission of: " + commissionE.ToString("C2") + Environment.NewLine +
                    "total of: " + totalE.ToString("C2"));
            }
        }
    }

    But what I am focusing on for now is under "Calculate Initial "A"'s Values" in this code block:

                // Calculate initial "A"'s values
                while (logoff == 0)
                {
                    do
                    {
                        do
                        {
                            saleA += Convert.ToDouble(Console.ReadLine());
                            commissionA = saleA * .10;
                            totalA = commissionA + saleA;
                            Console.WriteLine("Enter \"Z\" if you are finished, continue?");
                        } while (Console.ReadLine() != "Z" && initial == "A");
    
                        Console.WriteLine("Current Sales are: {0}", saleA);
                        done = 1;
                    } while (initial == "A" && done == 0);
    
                    logoff = 1;
                }

    So as you can see by my vain attempt with the variable "logoff", I want it so that as soon as all the calculations have been completed for "Andrea", it loops back and then it continues down.

    I am doing this so that if the person specifies that he is editing Andrea the first time, he can type "A" again to edit Andrea's values instead of having to either select editing Brittany or Eric....

    So is there a way to loop back like that more effectively? (and yes I am being extra for this assignment as I usually do because I want to become a programmer)

    Sunday, October 7, 2018 7:51 AM

All replies

  • Hello,

    In your code I can see a lot of copy-paste. Its create lot of code and demand time understand what was written

    for example:

                // Initial hello
                if (initial == "A")
                    Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "B")
                    Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "E")
                    Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    

    you supposed to do like 

    SayHello(initial);

    Where 

            private void SayHello(string initial)
            {
                // Hello Initial
                string name = InitialToName(initial);
                string message = string.Format("Hello {0}!", name); 
                Console.WriteLine(message);
                Console.WriteLine("Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
            }
    
            private string InitialToName(string initial)
            { 
                string name = "Uncnown";
    
                if (initial == "A") name = "Andrea";
                if (initial == "B") name = "Brittany";
                if (initial == "E") name = "Eric";
                return name;
            }


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 8:20 AM
  • Second part .

    You have a description - 

    "Calculate the salesperson’s commission as 10% of the sale amount, and add the commission to a running total for that salesperson. "

    Implement this part as separate class

        class SalesMade
        {
            const double commissionPersent = 0.1;
            double salesValue = 0.0;
    
            public SalesMade()
            {
            }
            public SalesMade(String SalesValue)
            {
                if (!double.TryParse(SalesValue, out salesValue))
                {
                    // error
                }
            }
    
            public double SalesValue { get { return salesValue; } set { salesValue = value; } }
            public double Commission { get { return salesValue * commissionPersent; } }
    
            public static SalesMade operator +(SalesMade source, Double add)
            {
                source.salesValue += add;
                return source;
            }
        }

    With this class your code will look like 

            private SalesMade ProcessSales()
            {
                SalesMade salesMade = new SalesMade();
                
                do
                {
                    string consleInput = Console.ReadLine();
                    // validate input here
                    double sale = Convert.ToDouble(consleInput);
                    salesMade = salesMade + sale;
                    Console.WriteLine("Enter \"Z\" if you are finished, continue?");
                } while (consoleInput != "Z");
                return salesMade;
            }

    I think that modification of your code you should be able to do by yourself.


    Sincerely, Highly skilled coding monkey.




    Sunday, October 7, 2018 8:41 AM
  • Ohhh, yesss....

    Bottom message:

                Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                    "sale of: " + saleE.ToString("C2") + Environment.NewLine +
                    "commission of: " + commissionE.ToString("C2") + Environment.NewLine +
                    "total of: " + totalE.ToString("C2"));

    Make it as a part of the class SalesMade

            private double Total { get { return SalesValue + Commission; } } // bug?
            public string MessageFormat
            {
                get
                {
                    
                    string msg = String.Empty;
                    msg += "Sales Person {0} has made a:" + Environment.NewLine;
                    msg += "sale of: " + salesValue.ToString("C2") + Environment.NewLine;
                    msg += "commission of: " + Commission.ToString("C2") + Environment.NewLine;
                    msg += "total of: " + Total.ToString("C2");
                    return msg;
                }
            }


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 8:54 AM
  • I just wrote a full response and... it got flagged as spam.....................

    the gist of what I said was that I don't know how to call from different classes as I haven't gotten quite that far yet in my class and my problem is not an issue of me not neatening it up with multiple classes.
    (I expect that this is very annoying for you, but here is my level: I am currently in 11th grade High School taking Programming II Honors and am ~2 months in)

    and I have fixed my problem in a very rudimentary way, I swapped a few "do" statements for "while" statements and made a major loop so that if say "Andrea" wanted to go back and edit her values after already creating her values, she'd need to keep on entering her initial "A" until she was prompted to state if she wanted the totals or to go back to the top and have everything reset.

    Here is the major loop I made:

    // Main loop
                do
                {
                    Console.WriteLine("Give me your initial.....");
    
                    // Initial Check
                    string initial = Console.ReadLine();
                    while (initial != "A" && initial != "B" && initial != "E")
                    {
                        Console.WriteLine("YOU'RE NOT DAVE!!!");
                        initial = Console.ReadLine();
                    }
    
                    // Hello Initial
                    if (initial == "A")
                        Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                    else if (initial == "B")
                        Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                    else if (initial == "E")
                        Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
                    // Calculate initial "A"'s values
                    while (initial == "A" && done == 0)
                    {
                        do
                        {
                            saleA += Convert.ToDouble(Console.ReadLine());
                            commissionA = saleA * .10;
                            totalA = commissionA + saleA;
                            Console.WriteLine("Enter \"Z\" if you are finished, continue?");
                        } while (Console.ReadLine() != "Z" && initial == "A");
    
                        Console.WriteLine("Current Sales are: {0}", saleA);
                        done = 1;
                    }
    
    
                    // RESET VALUES
                    done = 0;
                    Console.WriteLine();
                    Console.WriteLine("Give me your initial.....");
    
                    // Initial Check
                    initial = Console.ReadLine();
                    while (initial != "A" && initial != "B" && initial != "E")
                    {
                        Console.WriteLine("YOU'RE NOT DAVE!!!");
                        initial = Console.ReadLine();
                    }
    
                    // Initial hello
                    if (initial == "A")
                        Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Hold on, we will start from the top after you specify that you aren't complete at the bottom..... (Values will be reset)");
                    else if (initial == "B")
                        Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                    else if (initial == "E")
                        Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
                    // Calculate initial "B"'s values
                    while (initial == "B" && done == 0)
                    {
                        do
                        {
                            saleB += Convert.ToDouble(Console.ReadLine());
                            commissionB = saleB * .10;
                            totalB = commissionB + saleB;
                            Console.WriteLine("Enter \"Z\" if you are finished, continue?");
                        } while (Console.ReadLine() != "Z" && initial == "B");
    
                        Console.WriteLine("Current Sales are: {0}", saleB);
                        done = 1;
                    }
    
                    // RESET VALUES
                    done = 0;
                    Console.WriteLine();
                    Console.WriteLine("Give me your initial.....");
    
                    // Initial Check
                    initial = Console.ReadLine();
                    while (initial != "A" && initial != "B" && initial != "E")
                    {
                        Console.WriteLine("YOU'RE NOT DAVE!!!");
                        initial = Console.ReadLine();
                    }
    
                    // Inital hello
                    if (initial == "A")
                        Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Hold on, we will start from the top after you specify that you aren't complete at the bottom..... (Values will be reset)");
                    else if (initial == "B")
                        Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Hold on, we will start from the top after you specify that you aren't complete at the bottom..... (Values will be reset)");
                    else if (initial == "E")
                        Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
                    // Calculate initial "E"'s values
                    while (initial == "E" && done == 0)
                    {
                        do
                        {
                            saleE += Convert.ToDouble(Console.ReadLine());
                            commissionE = saleE * .10;
                            totalE = commissionE + saleE;
                            Console.WriteLine("Enter \"Z\" if you are finished, continue?");
                        } while (Console.ReadLine() != "Z" && initial == "E");
    
                        Console.WriteLine("Current Sales are: {0}", saleE);
                        done = 1;
                    }
    
                    // RESET VALUES
                    done = 0;
                    Console.WriteLine();
    
                    // Done?
                    Console.WriteLine("Do you want your totals or do you need to edit an older value?" + Environment.NewLine + "Enter a 1 for yes (I am done) or 0 for no (I want to edit something)................");
                    complete = Convert.ToInt32(Console.ReadLine());
                    while (complete != 1 && complete != 0)
                    {
                        Console.WriteLine("Enter a valid number...........");
                        complete = Convert.ToInt32(Console.ReadLine());
                    }
                } while (complete == 0);

    So the current question I have is:

    Can I make it so that once I write "A" after editing Andrea's values, it will immediately go back up to the top?

    or can this only be accomplished by creating classes?

    If I need classes can you please send me a resource for me to study so that I can learn how to effectively create this.

    Sunday, October 7, 2018 9:05 AM
  • > Can I make it so that once I write "A" after editing Andrea's values, it will immediately go back up to the top?

    Of course it can be done. 

    Solution is simple - you just wrap all repeatable code into do {...} while(repeatcondition);

    To what you need to pay attention - console input.

    You may get abnormally difficult code trying to process several console inputs. So, rule there is very simple - you have only one place to get something from console and need to properly handle this input before get next portion. So, when you expected Number or 'Z' - it need to be obtained by the same ReadLine() and hanled by the code.

    Example you have in ProcessSales();


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 9:25 AM
  • > I don't know how to call from different classes

    Sorry, but you DO!!!

    You use to call:

    Write()

    WriteLine()

    ReadLine()

    From Console class.

    The any other call are the same - you have MethodName() and you have className or instanceName and call instanceName.MethodName();


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 9:34 AM
  • So what I am getting is that I need to smartly use "do" statements and I was kind of on the track with my very early rendition.

    Well the problem I have with this is that loops cannot overlap and so what If:

     - A inserts values
     - B inserts values
     - A is recalled

    How do I go back to A after inserting B's values? Because from what I have seen loops can only be validated at the end or in the beginning and not in the middle and this is what limits my ability to create this.

    Side note:
    Your ProcessSales() class did not quite explain your example, however it did give me an idea for eliminating the limitation of needing to always be prompted to insert a "Z" after each input.

    Sunday, October 7, 2018 9:41 AM
  • Addition to my side note:

    So I am using Visual Studio as my IDE................. It makes so many mistakes and this might be one of them but...........

    Your ProcessSales() class might not work as the "consleInput" variable you initialized within your "do" statement will not work inside the "while" control statement at the end of the "do" statement as it will error with this:

    "The name 'consleInput' does not exist in current context"

    Sunday, October 7, 2018 9:47 AM
  • > did not quite explain your example, however it did give me an idea

    That was exactly it purpose - not an answer, but direction... 


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 9:56 AM
  • "The name 'consleInput' does not exist in current context"

    Yepp...

    Code was written on the fly - can have mistakes. 

    In this case - it need to be declared outside scope.


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 9:58 AM
  • > I don't know how to call from different classes

    Sorry, but you DO!!!

    You use to call:

    Write()

    WriteLine()

    ReadLine()

    From Console class.

    The any other call are the same - you have MethodName() and you have className or instanceName and call instanceName.MethodName();


    Sincerely, Highly skilled coding monkey.

    Okay, maybe I understand -ish, but I have a way to show you where I am confused with the classes you made by going through the scripts you sent me:

    your first script:

            private void SayHello(string initial)
            {
                // Hello Initial
                string name = InitialToName(initial);
                string message = string.Format("Hello {0}!", name); 
                Console.WriteLine(message);
                Console.WriteLine("Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
            }
    
            private string InitialToName(string initial)
            { 
                string name = "Uncnown";
    
                if (initial == "A") name = "Andrea";
                if (initial == "B") name = "Brittany";
                if (initial == "E") name = "Eric";
                return name;
            }

    So in the first line:
     - You wrote "private void" as this class will not need to have any of it's values called"
     - SaysHello - is the name of the class
     - (string initial) - this part I am having trouble understand what it does, I think it's creating a variable?

    line 4:
     - InitialToName(initial) - I have absolutely no idea how and what this method does
     - string.Format - is this another way of writing "Console.WriteLine()"?
     - Where did the name variable come from?

    Line 11:
     - Doesn't setting the class to private prevent you from being able to call it anywhere else?

    Line 15 - 17:
     - I usually write else if, but I think your way of writing it seems much more logical and will correct my future scripts.

    Your second script:

        class SalesMade
        {
            const double commissionPersent = 0.1;
            double salesValue = 0.0;
    
            public SalesMade()
            {
            }
            public SalesMade(String SalesValue)
            {
                if (!double.TryParse(SalesValue, out salesValue))
                {
                    // error
                }
            }
    
            public double SalesValue { get { return salesValue; } set { salesValue = value; } }
            public double Commission { get { return salesValue * commissionPersent; } }
    
            public static SalesMade operator +(SalesMade source, Double add)
            {
                source.salesValue += add;
                return source;
            }
        }

    Line 1:
     - I am now sure I am getting classes mixed up with something else.......

    line 6 - 15:
     - ....................................
     - I am not touching that because all I have noticed was a possible "catch ex as exception" equivalent that I used in VB

    Line 17 - 18:
     - unknown keywords: get, return and set.

    Line 20 - 23:
     - unknown keywords: operator, source (might be variable name), add (might be variable name)
     - source.salesValue - ???
     - return source; - ???

    I am gonna stop here as I think you get the picture, but the list goes further on with the rest of your scripts.

    Sunday, October 7, 2018 10:10 AM
  • Question:

    Is the following block of code valid (this is an attempt to prevent a continuous prompt for Z)

                        while (initial == "A" && done == 0)
                        {
                                string input = Console.ReadLine();
                            do
                            {
                                if (input != "Z")
                                {
                                    saleA += Convert.ToDouble(input);
                                    commissionA = saleA * .10;
                                    totalA = commissionA + saleA;
                                }
    
                                
                            } while (input != "Z" && initial == "A");
    
                            Console.WriteLine("Current Sales are: {0}", saleA);
                            done = 1;
                        }


    EDIT:

    I used a break and a watch debugger and I realized that I have inadvertently made the number continuously loop into infinity......

    Issue Resolved



    • Edited by Mikestriken Sunday, October 7, 2018 10:41 AM
    Sunday, October 7, 2018 10:28 AM
  • Okay, I am exhausted and the time is: 6:47 am, I am going to sleep, but here is my progress:

     - Solved everything except this:

    loops cannot overlap and so what If:

     - A inserts values
     - B inserts values
     - A is recalled

    How can i get the application to loop back to where A can correct his values?

    What my code looks like right now:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                // The EXIT FROOT LOOP
                 while (true)
                {
                    // Dim and start
                    double saleA = 0, saleB = 0, saleE = 0, commissionA = 0, totalA = 0, commissionB = 0, totalB = 0, commissionE = 0, totalE = 0;
                    int done = 0, complete = 0;
    
                    // Main loop
                    do
                    {
                        Console.WriteLine("Give me your initial.....");
    
                        // Initial Check
                        string initial = Console.ReadLine();
                        while (initial != "A" && initial != "B" && initial != "E")
                        {
                            Console.WriteLine("YOU'RE NOT DAVE!!!");
                            initial = Console.ReadLine();
                        }
    
                        // Hello Initial
                        if (initial == "A")
                            Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                        else if (initial == "B")
                            Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                        else if (initial == "E")
                            Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
                        // Calculate initial "A"'s values
                        while (initial == "A" && done == 0)
                        {
                                string input;
                            do
                            {
                                input = Console.ReadLine();
                                if (input != "Z")
                                {
                                    saleA += Convert.ToDouble(input);
                                    commissionA = saleA * .10;
                                    totalA = commissionA + saleA;
                                }
    
                                
                            } while (input != "Z" && initial == "A");
    
                            Console.WriteLine("Current Sales are: {0}", saleA.ToString("C2"));
                            done = 1;
                        }
    
    
                        // RESET VALUES
                        done = 0;
                        Console.WriteLine();
                        Console.WriteLine("Give me your initial.....");
    
                        // Initial Check
                        initial = Console.ReadLine();
                        while (initial != "A" && initial != "B" && initial != "E")
                        {
                            Console.WriteLine("YOU'RE NOT DAVE!!!");
                            initial = Console.ReadLine();
                        }
    
                        // Initial hello
                        if (initial == "A")
                            Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Hold on, we will start from the top after you specify that you aren't complete at the bottom..... (Values will be reset)");
                        else if (initial == "B")
                            Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                        else if (initial == "E")
                            Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
                        // Calculate initial "B"'s values
                        while (initial == "B" && done == 0)
                        {
                            string input;
                            do
                            {
                                input = Console.ReadLine();
                                if (input != "Z")
                                {
                                    saleB += Convert.ToDouble(input);
                                    commissionB = saleB * .10;
                                    totalB = commissionB + saleB;
                                }
    
    
                            } while (input != "Z" && initial == "B");
    
                            Console.WriteLine("Current Sales are: {0}", saleB.ToString("C2"));
                            done = 1;
                        }
    
                        // RESET VALUES
                        done = 0;
                        Console.WriteLine();
                        Console.WriteLine("Give me your initial.....");
    
                        // Initial Check
                        initial = Console.ReadLine();
                        while (initial != "A" && initial != "B" && initial != "E")
                        {
                            Console.WriteLine("YOU'RE NOT DAVE!!!");
                            initial = Console.ReadLine();
                        }
    
                        // Inital hello
                        if (initial == "A")
                            Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Hold on, we will start from the top after you specify that you aren't complete at the bottom..... (Values will be reset)");
                        else if (initial == "B")
                            Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Hold on, we will start from the top after you specify that you aren't complete at the bottom..... (Values will be reset)");
                        else if (initial == "E")
                            Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
                        // Calculate initial "E"'s values
                        while (initial == "E" && done == 0)
                        {
                            string input;
                            do
                            {
                                input = Console.ReadLine();
                                if (input != "Z")
                                {
                                    saleE += Convert.ToDouble(input);
                                    commissionE = saleE * .10;
                                    totalE = commissionE + saleE;
                                }
    
    
                            } while (input != "Z" && initial == "E");
    
                            Console.WriteLine("Current Sales are: {0}", saleE.ToString("C2"));
                            done = 1;
                        }
    
                        // RESET VALUES
                        done = 0;
                        Console.WriteLine();
    
                        // Done?
                        Console.WriteLine("Do you want your totals or do you need to edit an older value?" + Environment.NewLine + "Enter a 1 for yes (I am done) or 0 for no (I want to edit something)................");
                        complete = Convert.ToInt32(Console.ReadLine());
                        while (complete != 1 && complete != 0)
                        {
                            Console.WriteLine("Enter a valid number...........");
                            complete = Convert.ToInt32(Console.ReadLine());
                        }
                    } while (complete == 0);
    
    
                    // Spacer
                    Console.WriteLine();
    
                    // Andrea stats
                    Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                        "sale of: \t\t" + saleA.ToString("C2") + Environment.NewLine +
                        "commission of: \t\t" + commissionA.ToString("C2") + Environment.NewLine +
                        "total of: \t\t" + totalA.ToString("C2"));
    
                    // Spacer
                    Console.WriteLine();
    
                    // Brittany stats
                    Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                        "sale of: \t\t" + saleB.ToString("C2") + Environment.NewLine +
                        "commission of: \t\t" + commissionB.ToString("C2") + Environment.NewLine +
                        "total of: \t\t" + totalB.ToString("C2"));
    
                    // Spacer
                    Console.WriteLine();
    
                    // Eric stats
                    Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                        "sale of: \t\t" + saleE.ToString("C2") + Environment.NewLine +
                        "commission of: \t\t" + commissionE.ToString("C2") + Environment.NewLine +
                        "total of: \t\t" + totalE.ToString("C2"));
    
                    // Exit stop
                    Console.ReadLine();
                }
            }
        }
    }
    

    Sunday, October 7, 2018 10:51 AM
  • Hi,

    you need to read line again in the loop.

    Greetings, Chris

    Sunday, October 7, 2018 11:47 AM
  • And what is if the use inputs for example "sdg"? 

                string input = Console.ReadLine();
                do
                {
                    if (input != "Z")
                    {
                        if (Double.TryParse(input, out double o))
                        {
                            saleA += o;
                            commissionA = saleA * .10;
                            totalA = commissionA + saleA;
                        }
                    }
                    input = Console.ReadLine();
    
                } while (input != "Z" && initial == "A");

    It's better to check if it is a valid double.

    Greetings, Chris

    Sunday, October 7, 2018 11:58 AM
  • loops cannot overlap and so what If:

     - A inserts values
     - B inserts values
     - A is recalled

    How can i get the application to loop back to where A can correct his values?

    Where is the part where A can correct his value?

    From where you want to go there?

    Sounds like you need some ifs to decide if a part of your code is executed or not.

    Greetings, Chris

    Sunday, October 7, 2018 12:19 PM
  • >So in the first line:
    > - You wrote "private void" as this class will not need to have any of it's values called"
    > - SaysHello - is the name of the class
    > - (string initial) - this part I am having trouble understand what it does, I think it's creating a variable?

    This is not a class. This is a Method/Function. The same as WriteLien() & ReadLine().

    It's targeted to a part of the class Program. The same as method Main();

    -----

    >InitialToName(initial) 

    definition for the method provided. 

    -----

    string.Format

    It's a method of class string. Provide option to substitute value on the designated ('{0}') place. You can read Dtring clas ans Formate() method specification on MSDN.-----

    >Where did the name variable come from?

    Declared when needed:

    string name = "Uncnown";
    

    -----

    Doesn't setting the class to private prevent you from being able to call it anywhere else?

    Yeep... private methods (really - all private members) can't be used outside class.

    So, you would be able to call them from Main(), but would not be able to call from outside.

    You also need to study difference between static and non-static methods - this will play role when you try to call from static Main().

    -----

    > seems much more logical 

    I would not write code in a way in which it is offered on my work place.

    It written to indicate, that copy-paste can be avoided.

    -----

    Need to go.


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 12:28 PM
  • But I would remove the redundant code parts first. If you don't want to use methods because you are not familiar with them, you can use actions and functions:

    Action<string> initialHello = (initial) =>
    {
        if (initial == "A")
            Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Hold on, we will start from the top after you specify that you aren't complete at the bottom..... (Values will be reset)");
        else if (initial == "B")
            Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
        else if (initial == "E")
            Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
    };
    initialHello(initial);
    Greetings, Chris



    • Edited by DerChris88 Sunday, October 7, 2018 12:38 PM
    Sunday, October 7, 2018 12:31 PM
  •  I am now sure I am getting classes mixed up with something else.

    Programmers use classes to isolate something from everything else.

    You would not have access to private and protected members from outside the class.

    >line 6 - 15:

    > Line 17 - 18:

    Line 20 - 23:

    he list goes further 

    May be this is too much for one go, but answer for "unknown" always is only one - study.


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 12:57 PM
  • You  may want to note that if you deal only with "A" you may omit checking for "A" on each loop and... you also not need a variable suffix "A"...

    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 1:01 PM
  • string input; while((input = Console.ReadLine()) != "Z") { if (Double.TryParse(input, out double o))

    { saleA += o; commissionA = saleA * .10; totalA = commissionA + saleA; } }


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 1:23 PM
  •         private string InitialToName(string initial)
            { 
                string name = "Uncnown";
    
                if (initial == "A") name = "Andrea";
                else if (initial == "B") name = "Brittany";
                else if (initial == "E") name = "Eric";
                return name;
            }
    ;)
    Sunday, October 7, 2018 1:31 PM
  • Do you want me to provide example of switch() statement? :)

    It's a beginner's training - maximum simplicity, good explanation and... keeping interest by making huge discovery in programming on their own...

    If TS pick up an idea of method/function - I will be satisfied.


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 1:40 PM
  • It was just a suggestion after my review. That was not meant to be unfriendly. I just thought you may forgot it. :)

    But if you ask me: I would not use a switch case here. :)

    Greetings, Chris


    • Edited by DerChris88 Sunday, October 7, 2018 2:01 PM
    Sunday, October 7, 2018 1:57 PM
  • I just thought you may forgot it. :)

    No. It written in a way in which it can be easily understood by TS.

    Yes, code is not efficient,  yes, code have a problem.

    But purpose of provided code - do it in so simple way that TS will have wiliness to follow given example, get an error static-non-static method mix and... study.For this - it need to be as simple as possible. Extremely SIMPLE! even if it not efficient or have other problem.

    -----

    That was not meant to be unfriendly. 

    I'm old and have very heavy skin,,, :)

    For other moments - English is not a primary language - I wouldn't understand what I not need to understand.

    -----

    I would not use a switch case here. 

    Me too. Nor IF or IF-ELSE. This is written in explanation provided late.

    Target of provided code is very simple - to replace duplicated code by simple method. By the way it's spitted for two part - initial conversion and message dumping - this Ok - it's not created additional complexity.



    Sincerely, Highly skilled coding monkey.



    Sunday, October 7, 2018 2:28 PM
  • Maybe it's not completely what you want but first step to get the code shorter:

    namespace ConsoleApp1
    {
        class Program
        {
            class DTO
            {
                public double sale { get; set; }
                public double commission { get; set; }
                public double total { get; set; }
            }
    
            static string InitialUser()
            {
                Console.WriteLine("Give me your initial.....");
    
                // Initial Check
                string initial = Console.ReadLine();
                while (initial != "A" && initial != "B" && initial != "E")
                {
                    Console.WriteLine("YOU'RE NOT DAVE!!!");
                    initial = Console.ReadLine();
                }
    
                // Hello Initial
                if (initial == "A")
                    Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "B")
                    Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "E")
                    Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                return initial;
            }
    
            static void calculateInitial(DTO dto)
            {
                if (dto == null)
                    return;
                var done = false; 
                while (!done)
                {
                    string input;
                    do
                    {
                        input = Console.ReadLine();
                        if (input != "Z")
                        {
                            dto.sale += Convert.ToDouble(input);
                            dto.commission = dto.sale * .10;
                            dto.total = dto.commission + dto.sale;
                        }
    
    
                    } while (input != "Z");
    
                    Console.WriteLine("Current Sales are: {0}", dto.sale.ToString("C2"));
                    done = true;
                }
            }
    
            static void Main(string[] args)
            {
                string initial;
                // The EXIT FROOT LOOP
                while (true)
                {
                    // Dim and start
                    var complete = 0;
                    DTO A = new DTO();
                    DTO B = new DTO();
                    DTO E = new DTO();
    
                    // Main loop
                    do
                    {
                        // Initial Check
                        initial = InitialUser();
    
                        // Calculate initial "A"'s values
                        if (initial == "A")
                        {
                            calculateInitial(A);
                        }
                        else if (initial == "B")
                        {
                            calculateInitial(B);
                        }
                        else if (initial == "E")
                        {
                            calculateInitial(E);
                        }
    
                        // Done?
                        Console.WriteLine("Do you want your totals or do you need to edit an older value?" + Environment.NewLine + "Enter a 1 for yes (I am done) or 0 for no (I want to edit something)................");
                        complete = Convert.ToInt32(Console.ReadLine());
                        while (complete != 1 && complete != 0)
                        {
                            Console.WriteLine("Enter a valid number...........");
                            complete = Convert.ToInt32(Console.ReadLine());
                        }
                    } while (complete == 0);
    
    
                    // Spacer
                    Console.WriteLine();
    
                    // Andrea stats
                    Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                        "sale of: \t\t" + A.sale.ToString("C2") + Environment.NewLine +
                        "commission of: \t\t" + A.commission.ToString("C2") + Environment.NewLine +
                        "total of: \t\t" + A.total.ToString("C2"));
    
                    // Spacer
                    Console.WriteLine();
    
                    // Brittany stats
                    Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                        "sale of: \t\t" + B.sale.ToString("C2") + Environment.NewLine +
                        "commission of: \t\t" + B.commission.ToString("C2") + Environment.NewLine +
                        "total of: \t\t" + B.total.ToString("C2"));
    
                    // Spacer
                    Console.WriteLine();
    
                    // Eric stats
                    Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
                        "sale of: \t\t" + E.sale.ToString("C2") + Environment.NewLine +
                        "commission of: \t\t" + E.commission.ToString("C2") + Environment.NewLine +
                        "total of: \t\t" + E.total.ToString("C2"));
    
                    // Exit stop
                    Console.ReadLine();
                }
            }
        }
    }

    Greetings, Chris

    PS: Some suggestions from other posts here are not included. But you can change them very easily if you want.
    • Edited by DerChris88 Sunday, October 7, 2018 3:29 PM
    Sunday, October 7, 2018 3:23 PM
  • In this code I'm using a DTO (data transfer object) to store the stats for the sales person. The data construct is the same for every person so you do not need to have variables like salesA, salesB ... Now you have the DTO A with this data for Andrea and the same for B.. and E... . The calculation is the same for every person. So the method calculateInitial has no need to know who is making the input. In the main it's decided which DTO is used.

    If you have any questions, be free to ask. :)

    I hope this helps you.

    Greetings, Chris


    • Edited by DerChris88 Sunday, October 7, 2018 4:00 PM
    Sunday, October 7, 2018 3:37 PM
  • Changes: Outsourced stat output to static method.

    using System;
    
    namespace ConsoleApp1
    {
        class Program
        {
            class DTO
            {
                public double sale { get; set; }
                public double commission { get; set; }
                public double total { get; set; }
                public string name { get; set; }
            }
    
            static string InitialUser()
            {
                Console.WriteLine("Give me your initial.....");
    
                // Initial Check
                string initial = Console.ReadLine();
                while (initial != "A" && initial != "B" && initial != "E")
                {
                    Console.WriteLine("YOU'RE NOT DAVE!!!");
                    initial = Console.ReadLine();
                }
    
                // Hello Initial
                if (initial == "A")
                    Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "B")
                    Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                else if (initial == "E")
                    Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
                return initial;
            }
    
            static void calculateInitial(DTO dto)
            {
                if (dto == null)
                    return;
                var done = false; 
                while (!done)
                {
                    string input;
                    do
                    {
                        input = Console.ReadLine();
                        if (input != "Z")
                        {
                            dto.sale += Convert.ToDouble(input);
                            dto.commission = dto.sale * .10;
                            dto.total = dto.commission + dto.sale;
                        }
    
    
                    } while (input != "Z");
    
                    Console.WriteLine("Current Sales are: {0}", dto.sale.ToString("C2"));
                    done = true;
                }
            }
    
            static void Output(DTO dto)
            {
                // Spacer
                Console.WriteLine();
    
                // Eric stats
                Console.WriteLine("Sales Person " + dto.name + " has made a:" + Environment.NewLine +
                    "sale of: \t\t" + dto.sale.ToString("C2") + Environment.NewLine +
                    "commission of: \t\t" + dto.commission.ToString("C2") + Environment.NewLine +
                    "total of: \t\t" + dto.total.ToString("C2"));
            }
    
            static void Main(string[] args)
            {
                string initial;
                // The EXIT FROOT LOOP
                while (true)
                {
                    // Dim and start
                    var complete = 0;
                    DTO A = new DTO { name = "Andrea" };
                    DTO B = new DTO { name = "Brittany" };
                    DTO E = new DTO { name = "Eric" };
    
                    // Main loop
                    do
                    {
                        // Initial Check
                        initial = InitialUser();
    
                        // Calculate initial "A"'s values
                        if (initial == "A")
                        {
                            calculateInitial(A);
                        }
                        else if (initial == "B")
                        {
                            calculateInitial(B);
                        }
                        else if (initial == "E")
                        {
                            calculateInitial(E);
                        }
    
                        // Done?
                        Console.WriteLine("Do you want your totals or do you need to edit an older value?" + Environment.NewLine + "Enter a 1 for yes (I am done) or 0 for no (I want to edit something)................");
                        complete = Convert.ToInt32(Console.ReadLine());
                        while (complete != 1 && complete != 0)
                        {
                            Console.WriteLine("Enter a valid number...........");
                            complete = Convert.ToInt32(Console.ReadLine());
                        }
                    } while (complete == 0);
    
    
                    Output(A);
                    Output(B);
                    Output(E);
    
                    // Exit stop
                    Console.ReadLine();
                }
            }
        }
    }

    Greetings, Chris

    Sunday, October 7, 2018 4:12 PM
  • Okay, there is many a thing that I am missing (Quite a lot of the terms and methods your mentioning just passes me by) and I can't expect you to explain everything to me so:

    Can you give me a(n) resource(s) to learn most of what you are referencing and make the corrections your referencing.

    IMAO with the limited knowledge I have, simplified and implemented as much as I can to my very script.

    So if you have any suggestions as to where I can learn to do this better, please.

    Sunday, October 7, 2018 4:22 PM

  • Hi Mike,

    In my opinion, if you have not been taught some of these things in your class yet, then you shouldn't use them until you have been taught them. It sounds like all you've currently been taught is about loops and ifs ... not about how to create and call methods (nor about how to create and use other classes). Am I correct about that?


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, October 7, 2018 5:00 PM
    Moderator

  • Hi Mike,

    In my opinion, if you have not been taught some of these things in your class yet, then you shouldn't use them until you have been taught them. It sounds like all you've currently been taught is about loops and ifs ... not about how to create and call methods (nor about how to create and use other classes). Am I correct about that?


    ~~Bonnie DeWitt [C# MVP]

    We are currently on chapter 5 of 14 in this book:

    https://drive.google.com/open?id=1xu6PMARd5sUZGAUvA19LKxbbPbWTVPaP

    But what sucks is that my teacher isn't really what you call "enthusiastic" about being able to answer my questions on how to do the more complicated stuff.

    For instance I have not been told how to get the console app to exit at anytime when the user types "exit" no matter what prompt the app is in the middle of processing.


    • Edited by Mikestriken Sunday, October 7, 2018 6:20 PM
    Sunday, October 7, 2018 6:20 PM
  • Mike,

    That's too bad about your teacher's lack of enthusiasm ... the teacher must not be "into" what is being taught. Most good teachers would enthusiastically welcome a student with your desire to learn.  =0(

    I think you can easily handle this with loops, similar to what Chris showed earlier but changed just a bit:

    // The following will be inside your existing loops, where you set initial and "greet" the user.
    
    string input;
    while (initial != "Z" && initial == "A")
    {
        input = Console.ReadLine();
        if (Double.TryParse(input, out double o))
        {
            saleA += o;
            commissionA = saleA * .10;
            totalA = commissionA + saleA;
        }
        else
            initial = input;
    } 
    while (initial != "Z" && initial == "B")
    {
        // Same only use saleB, etc
    } 
    while (initial != "Z" && initial == "E")
    {
        // Same only use saleE, etc
    }
    if (initial == 'Z')
    {
        // Then here is probably where you'll want the code for displaying everyone's sales
    } 
    


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, October 7, 2018 7:28 PM
    Moderator
  • Methods are in chapter 7. Looks like you can't use my code at school yet, if you are at chapter 5. I'm sorry...
    Sunday, October 7, 2018 7:35 PM
  • Methods are in chapter 7. Looks like you can't use my code at school yet, if you are at chapter 5. I'm sorry...
    np
    Sunday, October 7, 2018 7:53 PM
  • Mike,

    That's too bad about your teacher's lack of enthusiasm ... the teacher must not be "into" what is being taught. Most good teachers would enthusiastically welcome a student with your desire to learn.  =0(

    I think you can easily handle this with loops, similar to what Chris showed earlier but changed just a bit:

    // The following will be inside your existing loops, where you set initial and "greet" the user.
    
    string input;
    while (initial != "Z" && initial == "A")
    {
        input = Console.ReadLine();
        if (Double.TryParse(input, out double o))
        {
            saleA += o;
            commissionA = saleA * .10;
            totalA = commissionA + saleA;
        }
        else
            initial = input;
    } 
    while (initial != "Z" && initial == "B")
    {
        // Same only use saleB, etc
    } 
    while (initial != "Z" && initial == "E")
    {
        // Same only use saleE, etc
    }
    if (initial == 'Z')
    {
        // Then here is probably where you'll want the code for displaying everyone's sales
    } 


    ~~Bonnie DeWitt [C# MVP]

    Thanks I took a quick look over your script and MAN!

    That first block is probably the most INGENIOUS method of fixing a bug that I have seen thus far in programming!
    (The problem being that with my current script, should I not enter a number nor write the letter "Z" it will error out, however that loop fixes that issue)

    Anyways, I have been working on this exercise for too long and I need to complete other homework before I can continue being extra in this assignment (just an explanation why I can't respond to any new messages in this thread for a while).


    Sunday, October 7, 2018 7:55 PM
  • But is my code working correctly for you(workflow)? Maybe it can be modified that you can use it.
    Sunday, October 7, 2018 7:58 PM
  • That first block is probably the most INGENIOUS method of fixing a bug that I have seen thus far in programming!
    (The problem being that with my current script, should I not enter a number nor write the letter "Z" it will error out, however that loop fixes that issue)

    Anyways, I have been working on this exercise for too long and I need to complete other homework before I can continue being extra in this assignment (just an explanation why I can't respond to any new messages in this thread for a while).


    I don't know if I'd call it "ingenious"   ;0)   … but thanks!  It's just that I've been doing this for a very long time!  You'll get there too!

    BTW, we call it "code", not "script". I certainly hope that your teacher is not referring to it as script!

    Come back here when you get a chance and let us know how you're doing with this particular project!

    Happy Coding!!  =0)


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, October 7, 2018 8:04 PM
    Moderator
  • My while-if-goto "spaghetti" code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                double sale = 0, commission = 0, total = 0; string name = "";
    
                double saleA = 0, commissionA = 0, totalA = 0;  string nameA = "";
                double saleB = 0, commissionB = 0, totalB = 0;  string nameB = "";
                double saleE = 0,   commissionE = 0, totalE = 0; string nameE = "";
    
                string continueEdit = "0";
    
                Console.WriteLine("Version 2.0.");
    
    
                Console.Write("Give me your initial (enter Q to Quit): ");
                string input;
                while (((input = Console.ReadLine()) != "Q") && (continueEdit == "0"))
                {
                    if (input != "A" && input != "B" && input != "E")
                    {
                        Console.WriteLine("YOU'RE NOT DAVE!!!");
                        goto ErrorHanling;
                    }
    
                    // Hello Initial
                    if (input == "A") name = "Andrea";
                    if (input == "B") name = "Brittany";
                    if (input == "E") name = "Eric";
                    Console.Write("Hello"); Console.Write(name); Console.WriteLine("!");
                    Console.WriteLine("Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
    
                    sale = 0; commission = 0; total = 0;
                    string customerInput;
                    while ((customerInput = Console.ReadLine()) != "Z")
                    {
                        double saleAmount;
                        if(Double.TryParse(customerInput, out saleAmount))
                        {
                            sale += saleAmount;
                            commission = sale * .10;
                            total = commission + sale;
                        }
                        else
                        {
                            Console.WriteLine("Expepected numerick or 'Z'");
                        }                     
    
                        Console.WriteLine("Current Sales are: {0}", saleA.ToString("C2"));
                    }
                    
                    
                    if (input == "A")
                    {
                        saleA = sale;
                        commissionA = commission;
                        totalA = total;
                        nameA = name;
                    }
    
                    if (input == "B")
                    {
                        saleB = sale;
                        commissionB = commission;
                        totalB = total;
                        nameB = name;
                    }
    
                    if (input == "E")
                    {
                        saleE = sale;
                        commissionE = commission;
                        totalE = total;
                        nameE = name;
                    }
    
                    Console.WriteLine("Do you want your totals or do you need to edit an older value?");
                    Console.WriteLine("Enter a 1 for yes (I am done) or 0 for no (I want to edit something)................");
                    continueEdit = Console.ReadLine();
                    
                ErrorHanling: /* nothing */ ; 
                }
                goto DoShowSaleA;
    
    
            DoShowSaleA:
                input = "A"; 
                goto ShowSale;
    
            DoShowSaleB:
                input = "B"; 
                goto ShowSale;
    
            DoShowSaleE:
                input = "E"; 
                goto ShowSale;
    
    
    
            ShowSale:
    
                if (input == "A")
                {
                    sale = saleA;
                    commission = commissionA;
                    total = totalA;
                    name = nameA;
                }
    
                if (input == "B")
                {
                    sale = saleB;
                    commission = commissionB;
                    total = totalB;
                    name = nameB;
                }
    
                if (input == "E")
                {
                    sale = saleE;
                    commission = commissionE;
                    total = totalE;
                    name = nameE;
                }
    
                // Spacer
                Console.WriteLine();
    
                // Stats for person
                Console.Write("Sales Person "); Console.Write(name); Console.WriteLine(" has made a:");
                Console.WriteLine("sale of: \t\t" + sale.ToString("C2"));
                Console.Write("commission of: \t\t" + commission.ToString("C2"));
                Console.Write("total of: \t\t" + total.ToString("C2"));
    
                if(input == "A") goto DoShowSaleB;
                if(input == "B") goto DoShowSaleE;
                if(input == "E") goto WaitForExit;
    
            WaitForExit:
                Console.WriteLine("Result printed.");
                Console.WriteLine("Press any key for exit.");
                Console.ReadKey();
                
            }
        }
    }
    

    It is a VERY POOR example of coding. The only excuse is - it used only while, if and goto operators - you already study those operators. Using GOTO is a very poor style of programming.

    Try to understand - you not to copy-paste your code - you need to organize code execution in suitable way.

    -----

    About your teacher... Even if I would be very enthusiastic about teaching a programming I would not be able to explain to you how to exit from the program on typing EXIT on any console input. At least until you didn't study the functions/methods. Or even classes.


    Sincerely, Highly skilled coding monkey.

    Sunday, October 7, 2018 9:45 PM

  • ...how to exit from the program on typing EXIT on any console input...

    if (input == "EXIT")
    {
        return;
    }
    Copy pasting this after every Console.ReadLine should do it if the use of other methods is not allowed. But is this legitimate?
    Sunday, October 7, 2018 10:47 PM

  • BTW, we call it "code", not "script". I certainly hope that your teacher is not referring to it as script!

    Come back here when you get a chance and let us know how you're doing with this particular project!

    Happy Coding!!  =0)


    ~~Bonnie DeWitt [C# MVP]

    So........................... I did a quick research and found this website:

    https://skillcrush.com/2012/09/21/coding-vs-scripting/

    It's definition basically says that coding can refer to anytime you program a computer.

    Scripting is when your coding in a way that tells what something should do (I.E. it does not declare variables or say what something should look like)

    ----

    I just got scripting and coding confused by myself (not my teacher), as when I said something like "look at this code" when I was referring to a "block of code" (what I am using now as opposed to script, but am still apprehensive of doing as I feel as though you should only refer to a "block of code" when you program within the curly braces) I felt as though it was improper use of vocabulary and felt that I should use "script" whenever I mention a segment of code that I wish to place emphasis on.

    (your the first to correct me :P)

    Sunday, October 7, 2018 10:49 PM
  • I just got scripting and coding confused by myself (not my teacher), as when I said something like "look at this code" when I was referring to a "block of code" (what I am using now as opposed to script, but am still apprehensive of doing as I feel as though you should only refer to a "block of code" when you program within the curly braces) I felt as though it was improper use of vocabulary and felt that I should use "script" whenever I mention a segment of code that I wish to place emphasis on.

    (your the first to correct me :P)

    Hey Mike,

    You'll get used to saying "code" … and a "block of code" or a "snippet of code" or whatever little "bit of code" you want to emphasize could be anywhere, between curly braces or not.

    And, as far as correcting you … you gotta learn correct terminology somewhere, right?  ;0)   ;0)


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, October 7, 2018 11:08 PM
    Moderator
  • My while-if-goto "spaghetti" code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
                double sale = 0, commission = 0, total = 0; string name = "";
    
                double saleA = 0, commissionA = 0, totalA = 0;  string nameA = "";
                double saleB = 0, commissionB = 0, totalB = 0;  string nameB = "";
                double saleE = 0,   commissionE = 0, totalE = 0; string nameE = "";
    
                string continueEdit = "0";
    
                Console.WriteLine("Version 2.0.");
    
    
                Console.Write("Give me your initial (enter Q to Quit): ");
                string input;
                while (((input = Console.ReadLine()) != "Q") && (continueEdit == "0"))
                {
                    if (input != "A" && input != "B" && input != "E")
                    {
                        Console.WriteLine("YOU'RE NOT DAVE!!!");
                        goto ErrorHanling;
                    }
    
                    // Hello Initial
                    if (input == "A") name = "Andrea";
                    if (input == "B") name = "Brittany";
                    if (input == "E") name = "Eric";
                    Console.Write("Hello"); Console.Write(name); Console.WriteLine("!");
                    Console.WriteLine("Insert the sales you have gained, and enter \"Z\" when you are finished....");
    
    
                    sale = 0; commission = 0; total = 0;
                    string customerInput;
                    while ((customerInput = Console.ReadLine()) != "Z")
                    {
                        double saleAmount;
                        if(Double.TryParse(customerInput, out saleAmount))
                        {
                            sale += saleAmount;
                            commission = sale * .10;
                            total = commission + sale;
                        }
                        else
                        {
                            Console.WriteLine("Expepected numerick or 'Z'");
                        }                     
    
                        Console.WriteLine("Current Sales are: {0}", saleA.ToString("C2"));
                    }
                    
                    
                    if (input == "A")
                    {
                        saleA = sale;
                        commissionA = commission;
                        totalA = total;
                        nameA = name;
                    }
    
                    if (input == "B")
                    {
                        saleB = sale;
                        commissionB = commission;
                        totalB = total;
                        nameB = name;
                    }
    
                    if (input == "E")
                    {
                        saleE = sale;
                        commissionE = commission;
                        totalE = total;
                        nameE = name;
                    }
    
                    Console.WriteLine("Do you want your totals or do you need to edit an older value?");
                    Console.WriteLine("Enter a 1 for yes (I am done) or 0 for no (I want to edit something)................");
                    continueEdit = Console.ReadLine();
                    
                ErrorHanling: /* nothing */ ; 
                }
                goto DoShowSaleA;
    
    
            DoShowSaleA:
                input = "A"; 
                goto ShowSale;
    
            DoShowSaleB:
                input = "B"; 
                goto ShowSale;
    
            DoShowSaleE:
                input = "E"; 
                goto ShowSale;
    
    
    
            ShowSale:
    
                if (input == "A")
                {
                    sale = saleA;
                    commission = commissionA;
                    total = totalA;
                    name = nameA;
                }
    
                if (input == "B")
                {
                    sale = saleB;
                    commission = commissionB;
                    total = totalB;
                    name = nameB;
                }
    
                if (input == "E")
                {
                    sale = saleE;
                    commission = commissionE;
                    total = totalE;
                    name = nameE;
                }
    
                // Spacer
                Console.WriteLine();
    
                // Stats for person
                Console.Write("Sales Person "); Console.Write(name); Console.WriteLine(" has made a:");
                Console.WriteLine("sale of: \t\t" + sale.ToString("C2"));
                Console.Write("commission of: \t\t" + commission.ToString("C2"));
                Console.Write("total of: \t\t" + total.ToString("C2"));
    
                if(input == "A") goto DoShowSaleB;
                if(input == "B") goto DoShowSaleE;
                if(input == "E") goto WaitForExit;
    
            WaitForExit:
                Console.WriteLine("Result printed.");
                Console.WriteLine("Press any key for exit.");
                Console.ReadKey();
                
            }
        }
    }

    It is a VERY POOR example of coding. The only excuse is - it used only while, if and goto operators - you already study those operators. Using GOTO is a very poor style of programming.

    Try to understand - you not to copy-paste your code - you need to organize code execution in suitable way.

    -----

    About your teacher... Even if I would be very enthusiastic about teaching a programming I would not be able to explain to you how to exit from the program on typing EXIT on any console input. At least until you didn't study the functions/methods. Or even classes.


    Sincerely, Highly skilled coding monkey.

    WOW! so obvious, just assign sale value's to respective person at the end!!!!

    Question:
     - I feel as though this part is redundant:

     goto DoShowSaleA;
    
    
            DoShowSaleA:
                input = "A"; 
                goto ShowSale;
    
            DoShowSaleB:
                input = "B"; 
                goto ShowSale;
    
            DoShowSaleE:
                input = "E"; 
                goto ShowSale;
    
    
    
            ShowSale:
    
                if (input == "A")
                {
                    sale = saleA;
                    commission = commissionA;
                    total = totalA;
                    name = nameA;
                }
    
                if (input == "B")
                {
                    sale = saleB;
                    commission = commissionB;
                    total = totalB;
                    name = nameB;
                }
    
                if (input == "E")
                {
                    sale = saleE;
                    commission = commissionE;
                    total = totalE;
                    name = nameE;
                }
    

    Question #2:

    Shouldn't it loop every time the person doesn't input the correct initial and not "goto Errorhanling"?

    Last thing:

    About my teacher, I don't mean to speak badly of my teacher and I feel it is very inappropriate for me to speak badly of a senior, however when I was told: "In my opinion, if you have not been taught some of these things in your class yet, then you shouldn't use them until you have been taught them. It sounds like all you've currently been taught is about loops and ifs ... not about how to create and call methods (nor about how to create and use other classes). Am I correct about that?"

    That I replied the way I did.

    Sunday, October 7, 2018 11:08 PM
  • But is my code working correctly for you(workflow)? Maybe it can be modified that you can use it.
    Can you elaborate?
    Sunday, October 7, 2018 11:12 PM
  • If the code is working as expected I can tell you how to do it ;P. There are just a few things to do(copy pasting, changing some names, adding some variables) but I think if I do it and post a complete solution here your teacher and BonnieB would be angry. :D
    Sunday, October 7, 2018 11:20 PM
  • As Andrey said (even though he put it in his code sample): >>Using GOTO is a very poor style of programming<<

    I would hazard a guess that if you included goto's in your code, your teacher would not be very happy about that and, most likely, your grade for this exercise would suffer a bit. My suggestion is to take some of what's been shown to you here, and re-work your code to include some of these ideas (like the loops you called "INGENIOUS" ).


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Sunday, October 7, 2018 11:37 PM
    Moderator
  • > But is this legitimate?

    This would not work in all cases. Specially when it happen inside methods.

    So, to reduce misunderstanding, - would not be able to explain until...

    Yes, a lie ... but with good intentions ...


    Sincerely, Highly skilled coding monkey.

    Monday, October 8, 2018 7:56 AM
  • - I feel as though this part is redundant

    Try with it and try without it. Difference will show you what it's for.

    And... IF-GOTO - very poor programming style. You can see a difference between top part of the code and part with IF-GOT. The same result, with a bit shorter and much clear code, can be obtained. Try to make implementation without IF-GOTO... when you understand what it doing.

    -----

    Shouldn't it loop every time the person doesn't input the correct initial and not "goto Errorhanling"?

    And what it doing? 

    Do you study operator 'continue;'? - if Yes - you could replace goto ErrorHanling; and remove ErrorHandling: label.


    Sincerely, Highly skilled coding monkey.

    Monday, October 8, 2018 8:11 AM

  • This would not work in all cases. Specially when it happen inside methods.

    That's why I wrote: When the usage of other methods is not allowed. The idea was that you jump out of the Main wherever you are there. But It's true, it's not working from other methods. You are just jumping back to the caller. But for the Main method the caller is the OS, because it's your entry point.

    I hope that's enough to understand this code snippet.

    Greetings, Chris

    Monday, October 8, 2018 9:58 AM