Console calculator for 2 numbers at a time

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite












I'm learning to code for fun, and just finished my first program.
Idk what to think about it since I it's my first finished real code, but hey it works! I'm pretty sure that it can be written shorter or better than this.



Right now it can only solve 1 problem at a time, but I'm going to make it so it can save the outcome and work further on it and after that I'm of plan to change from console to a real calculator look. I just want to improve myself by listening at your thoughts before working further on it.
What could I do shorter/easier/simpler/better?



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)

ZoneNumber1: //First number
Console.WriteLine();
Console.WriteLine();
Console.Write("Number: ");
double Number1;
double Number2;

while (!double.TryParse(Console.ReadLine(), out Number1))

Console.Clear();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Wrong sort of input.");
Console.Write("Enter a number: ");

Console.Clear();
Console.WriteLine(Number1);
Console.WriteLine();

//Second number + action
Action:
Console.Write("Action: ");
string Action = Console.ReadLine();
Console.Clear();
Console.WriteLine(Number1+""+Action);

if ((Action == "*")











share|improve this question









New contributor




Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    6
    down vote

    favorite












    I'm learning to code for fun, and just finished my first program.
    Idk what to think about it since I it's my first finished real code, but hey it works! I'm pretty sure that it can be written shorter or better than this.



    Right now it can only solve 1 problem at a time, but I'm going to make it so it can save the outcome and work further on it and after that I'm of plan to change from console to a real calculator look. I just want to improve myself by listening at your thoughts before working further on it.
    What could I do shorter/easier/simpler/better?



    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)

    ZoneNumber1: //First number
    Console.WriteLine();
    Console.WriteLine();
    Console.Write("Number: ");
    double Number1;
    double Number2;

    while (!double.TryParse(Console.ReadLine(), out Number1))

    Console.Clear();
    Console.WriteLine();
    Console.WriteLine();
    Console.WriteLine("Wrong sort of input.");
    Console.Write("Enter a number: ");

    Console.Clear();
    Console.WriteLine(Number1);
    Console.WriteLine();

    //Second number + action
    Action:
    Console.Write("Action: ");
    string Action = Console.ReadLine();
    Console.Clear();
    Console.WriteLine(Number1+""+Action);

    if ((Action == "*")











    share|improve this question









    New contributor




    Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      6
      down vote

      favorite









      up vote
      6
      down vote

      favorite











      I'm learning to code for fun, and just finished my first program.
      Idk what to think about it since I it's my first finished real code, but hey it works! I'm pretty sure that it can be written shorter or better than this.



      Right now it can only solve 1 problem at a time, but I'm going to make it so it can save the outcome and work further on it and after that I'm of plan to change from console to a real calculator look. I just want to improve myself by listening at your thoughts before working further on it.
      What could I do shorter/easier/simpler/better?



      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)

      ZoneNumber1: //First number
      Console.WriteLine();
      Console.WriteLine();
      Console.Write("Number: ");
      double Number1;
      double Number2;

      while (!double.TryParse(Console.ReadLine(), out Number1))

      Console.Clear();
      Console.WriteLine();
      Console.WriteLine();
      Console.WriteLine("Wrong sort of input.");
      Console.Write("Enter a number: ");

      Console.Clear();
      Console.WriteLine(Number1);
      Console.WriteLine();

      //Second number + action
      Action:
      Console.Write("Action: ");
      string Action = Console.ReadLine();
      Console.Clear();
      Console.WriteLine(Number1+""+Action);

      if ((Action == "*")











      share|improve this question









      New contributor




      Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm learning to code for fun, and just finished my first program.
      Idk what to think about it since I it's my first finished real code, but hey it works! I'm pretty sure that it can be written shorter or better than this.



      Right now it can only solve 1 problem at a time, but I'm going to make it so it can save the outcome and work further on it and after that I'm of plan to change from console to a real calculator look. I just want to improve myself by listening at your thoughts before working further on it.
      What could I do shorter/easier/simpler/better?



      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)

      ZoneNumber1: //First number
      Console.WriteLine();
      Console.WriteLine();
      Console.Write("Number: ");
      double Number1;
      double Number2;

      while (!double.TryParse(Console.ReadLine(), out Number1))

      Console.Clear();
      Console.WriteLine();
      Console.WriteLine();
      Console.WriteLine("Wrong sort of input.");
      Console.Write("Enter a number: ");

      Console.Clear();
      Console.WriteLine(Number1);
      Console.WriteLine();

      //Second number + action
      Action:
      Console.Write("Action: ");
      string Action = Console.ReadLine();
      Console.Clear();
      Console.WriteLine(Number1+""+Action);

      if ((Action == "*")








      c# beginner console calculator






      share|improve this question









      New contributor




      Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 35 mins ago









      200_success

      126k14146407




      126k14146407






      New contributor




      Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 hours ago









      Betrax

      334




      334




      New contributor




      Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Betrax is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Some rules of thumb:



          1. If you have your entire program in a single method (Main(), in this case), there are some design considerations you should probably revisit. Especially from a DRY ("Don't Repeat Yourself") perspective.


          2. If you find yourself using goto in a language invented after 1985, you're likely not availing yourself of the rich and varied control structures a language has to offer.


          3. If you're using C#, you should consider using object-oriented design and implementation. While the language does support other paradigms (such as the imperative form, which you're employing here), it's forte is OO and using it as a tool to solve problems is very much idiomatic.


          4. A good design approach, even in simple programs is to separate the so-called "business logic" from the user interface logic, also known as Separation of Concerns. Keep your calculations away from your WriteLines, as it were.


          So, let's take a look at one possible refinement (I'm going to address points 1 and 2):



          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)

          while (true)

          double number1 = GetNumber();
          Console.Clear();
          Console.WriteLine(number1);
          Console.WriteLine();
          string action = GetAction();
          double number2 = GetNumber();
          Console.WriteLine(number2);
          double result = Perform(number1, action, number2);
          Console.Clear();
          Console.WriteLine(number1 + action + number2);
          Console.WriteLine();
          Console.WriteLine("= " + result);
          Console.Write("Press enter to calculate again: ");
          Console.ReadLine();
          Console.Clear();



          private static double GetNumber()

          double number;

          Console.Write("Number: ");
          while (!double.TryParse(Console.ReadLine(), out number))

          NumberInputError();


          return number;


          private static void NumberInputError()

          Console.Clear();
          Console.WriteLine();
          Console.WriteLine();
          Console.WriteLine("Wrong sort of input.");
          Console.Write("Enter a number: ");


          private static string GetAction()

          while (true)
          (action == "/")


          private static double Perform(double number1, string action, double number2)

          switch (action)

          case "+": return number1 + number2;
          case "-": return number1 - number2;
          case "*": return number1 * number2;
          case "/": return number1 / number2;
          default: throw new InvalidOperationException("False action input, choose between: / ; * ; - ; +");









          share|improve this answer
















          • 1




            Thank you very much! You illuminated me by using private static s. Now I know what to learn next and how to improve. THANK YOU VERY MUCH!
            – Betrax
            6 mins ago










          • Glad to help - hope to see more refinements and iterations along your journey.
            – Jesse C. Slicer
            5 mins ago

















          up vote
          2
          down vote













          I think your variant can be improved by reducing the number of code duplication.



          My var:



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

          namespace ConsoleApp1

          class Program

          static double Number1;
          static string Action;
          static double Number2;
          static double Answer;
          static void Main(string args)

          bool AppOn = true;

          while (AppOn != false)

          Console.WriteLine();
          Console.WriteLine();
          Console.Write("Number: ");

          Number1 = TryGetNumber();

          Console.Clear();
          Console.WriteLine(Number1);


          Action = TryGetAction();

          Console.Clear();
          Console.WriteLine(Number1 + Action);


          Number2 = TryGetNumber();

          Console.Clear();
          Console.WriteLine(Number1 + Action + Number2);


          switch (Action)

          case "*":
          Answer = Number1 * Number2;
          break;
          case "-":
          Answer = Number1 - Number2;
          break;
          case "+":
          Answer = Number1 + Number2;
          break;
          case "/":
          Answer = Number1 / Number2;
          break;


          Console.WriteLine();
          Console.WriteLine("= " + Answer);
          Console.Write("Press enter to calculate again or esc for exit: ");
          ConsoleKeyInfo keyInfo = Console.ReadKey();
          if (keyInfo.Key == ConsoleKey.Enter)

          AppOn = true;


          switch (keyInfo.Key)

          case ConsoleKey.Enter:
          AppOn = true;
          break;
          case ConsoleKey.Escape:
          AppOn = false;
          break;


          Console.Clear();




          public static double TryGetNumber()

          double resultNumber;

          while (!double.TryParse(Console.ReadLine(), out resultNumber))

          Console.Clear();
          Console.WriteLine();
          Console.WriteLine();
          Console.WriteLine("Wrong sort of input.");
          Console.Write("Enter a number: ");


          return resultNumber;


          public static string TryGetAction()

          Console.WriteLine();
          Console.WriteLine();
          Console.Write("Action: ");

          string result = "";
          bool success = false;

          while (success != true)

          return result;





          What i do? Step by step.



          1. Remove all goto operator. In C# and in some (many) others lang decided that goto operator is evil operator, because in small programs you cant see this hell, but on projects larger code will become so hard for read and write. And in any case you use methods. There are many reasons, I advise you to read about this.

          2. Remove dublicate.
            In your version a lot of code that was created by Ctrl + C, Ctrl + V. Usually try to move away from this, wrapping such pieces in the methods and using several times. Let me show:(same color indicates same piece)
            enter image description here

          Same pieces, but in my variant



          enter image description here



          1. My version seems to be the same volume , because I added a lot of indents and spaces, focusing on the steps and structuring the code.

          I use more things than in your version. I can answer your questions.






          share|improve this answer








          New contributor




          Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.
























            up vote
            1
            down vote













            You should not be repeating. Put it below the the final else.



            while (!double.TryParse(Console.ReadLine(), out Number2))





            share|improve this answer




















              Your Answer




              StackExchange.ifUsing("editor", function ()
              return StackExchange.using("mathjaxEditing", function ()
              StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
              StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
              );
              );
              , "mathjax-editing");

              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "196"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );






              Betrax is a new contributor. Be nice, and check out our Code of Conduct.









               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f205906%2fconsole-calculator-for-2-numbers-at-a-time%23new-answer', 'question_page');

              );

              Post as a guest






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote



              accepted










              Some rules of thumb:



              1. If you have your entire program in a single method (Main(), in this case), there are some design considerations you should probably revisit. Especially from a DRY ("Don't Repeat Yourself") perspective.


              2. If you find yourself using goto in a language invented after 1985, you're likely not availing yourself of the rich and varied control structures a language has to offer.


              3. If you're using C#, you should consider using object-oriented design and implementation. While the language does support other paradigms (such as the imperative form, which you're employing here), it's forte is OO and using it as a tool to solve problems is very much idiomatic.


              4. A good design approach, even in simple programs is to separate the so-called "business logic" from the user interface logic, also known as Separation of Concerns. Keep your calculations away from your WriteLines, as it were.


              So, let's take a look at one possible refinement (I'm going to address points 1 and 2):



              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)

              while (true)

              double number1 = GetNumber();
              Console.Clear();
              Console.WriteLine(number1);
              Console.WriteLine();
              string action = GetAction();
              double number2 = GetNumber();
              Console.WriteLine(number2);
              double result = Perform(number1, action, number2);
              Console.Clear();
              Console.WriteLine(number1 + action + number2);
              Console.WriteLine();
              Console.WriteLine("= " + result);
              Console.Write("Press enter to calculate again: ");
              Console.ReadLine();
              Console.Clear();



              private static double GetNumber()

              double number;

              Console.Write("Number: ");
              while (!double.TryParse(Console.ReadLine(), out number))

              NumberInputError();


              return number;


              private static void NumberInputError()

              Console.Clear();
              Console.WriteLine();
              Console.WriteLine();
              Console.WriteLine("Wrong sort of input.");
              Console.Write("Enter a number: ");


              private static string GetAction()

              while (true)
              (action == "/")


              private static double Perform(double number1, string action, double number2)

              switch (action)

              case "+": return number1 + number2;
              case "-": return number1 - number2;
              case "*": return number1 * number2;
              case "/": return number1 / number2;
              default: throw new InvalidOperationException("False action input, choose between: / ; * ; - ; +");









              share|improve this answer
















              • 1




                Thank you very much! You illuminated me by using private static s. Now I know what to learn next and how to improve. THANK YOU VERY MUCH!
                – Betrax
                6 mins ago










              • Glad to help - hope to see more refinements and iterations along your journey.
                – Jesse C. Slicer
                5 mins ago














              up vote
              3
              down vote



              accepted










              Some rules of thumb:



              1. If you have your entire program in a single method (Main(), in this case), there are some design considerations you should probably revisit. Especially from a DRY ("Don't Repeat Yourself") perspective.


              2. If you find yourself using goto in a language invented after 1985, you're likely not availing yourself of the rich and varied control structures a language has to offer.


              3. If you're using C#, you should consider using object-oriented design and implementation. While the language does support other paradigms (such as the imperative form, which you're employing here), it's forte is OO and using it as a tool to solve problems is very much idiomatic.


              4. A good design approach, even in simple programs is to separate the so-called "business logic" from the user interface logic, also known as Separation of Concerns. Keep your calculations away from your WriteLines, as it were.


              So, let's take a look at one possible refinement (I'm going to address points 1 and 2):



              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)

              while (true)

              double number1 = GetNumber();
              Console.Clear();
              Console.WriteLine(number1);
              Console.WriteLine();
              string action = GetAction();
              double number2 = GetNumber();
              Console.WriteLine(number2);
              double result = Perform(number1, action, number2);
              Console.Clear();
              Console.WriteLine(number1 + action + number2);
              Console.WriteLine();
              Console.WriteLine("= " + result);
              Console.Write("Press enter to calculate again: ");
              Console.ReadLine();
              Console.Clear();



              private static double GetNumber()

              double number;

              Console.Write("Number: ");
              while (!double.TryParse(Console.ReadLine(), out number))

              NumberInputError();


              return number;


              private static void NumberInputError()

              Console.Clear();
              Console.WriteLine();
              Console.WriteLine();
              Console.WriteLine("Wrong sort of input.");
              Console.Write("Enter a number: ");


              private static string GetAction()

              while (true)
              (action == "/")


              private static double Perform(double number1, string action, double number2)

              switch (action)

              case "+": return number1 + number2;
              case "-": return number1 - number2;
              case "*": return number1 * number2;
              case "/": return number1 / number2;
              default: throw new InvalidOperationException("False action input, choose between: / ; * ; - ; +");









              share|improve this answer
















              • 1




                Thank you very much! You illuminated me by using private static s. Now I know what to learn next and how to improve. THANK YOU VERY MUCH!
                – Betrax
                6 mins ago










              • Glad to help - hope to see more refinements and iterations along your journey.
                – Jesse C. Slicer
                5 mins ago












              up vote
              3
              down vote



              accepted







              up vote
              3
              down vote



              accepted






              Some rules of thumb:



              1. If you have your entire program in a single method (Main(), in this case), there are some design considerations you should probably revisit. Especially from a DRY ("Don't Repeat Yourself") perspective.


              2. If you find yourself using goto in a language invented after 1985, you're likely not availing yourself of the rich and varied control structures a language has to offer.


              3. If you're using C#, you should consider using object-oriented design and implementation. While the language does support other paradigms (such as the imperative form, which you're employing here), it's forte is OO and using it as a tool to solve problems is very much idiomatic.


              4. A good design approach, even in simple programs is to separate the so-called "business logic" from the user interface logic, also known as Separation of Concerns. Keep your calculations away from your WriteLines, as it were.


              So, let's take a look at one possible refinement (I'm going to address points 1 and 2):



              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)

              while (true)

              double number1 = GetNumber();
              Console.Clear();
              Console.WriteLine(number1);
              Console.WriteLine();
              string action = GetAction();
              double number2 = GetNumber();
              Console.WriteLine(number2);
              double result = Perform(number1, action, number2);
              Console.Clear();
              Console.WriteLine(number1 + action + number2);
              Console.WriteLine();
              Console.WriteLine("= " + result);
              Console.Write("Press enter to calculate again: ");
              Console.ReadLine();
              Console.Clear();



              private static double GetNumber()

              double number;

              Console.Write("Number: ");
              while (!double.TryParse(Console.ReadLine(), out number))

              NumberInputError();


              return number;


              private static void NumberInputError()

              Console.Clear();
              Console.WriteLine();
              Console.WriteLine();
              Console.WriteLine("Wrong sort of input.");
              Console.Write("Enter a number: ");


              private static string GetAction()

              while (true)
              (action == "/")


              private static double Perform(double number1, string action, double number2)

              switch (action)

              case "+": return number1 + number2;
              case "-": return number1 - number2;
              case "*": return number1 * number2;
              case "/": return number1 / number2;
              default: throw new InvalidOperationException("False action input, choose between: / ; * ; - ; +");









              share|improve this answer












              Some rules of thumb:



              1. If you have your entire program in a single method (Main(), in this case), there are some design considerations you should probably revisit. Especially from a DRY ("Don't Repeat Yourself") perspective.


              2. If you find yourself using goto in a language invented after 1985, you're likely not availing yourself of the rich and varied control structures a language has to offer.


              3. If you're using C#, you should consider using object-oriented design and implementation. While the language does support other paradigms (such as the imperative form, which you're employing here), it's forte is OO and using it as a tool to solve problems is very much idiomatic.


              4. A good design approach, even in simple programs is to separate the so-called "business logic" from the user interface logic, also known as Separation of Concerns. Keep your calculations away from your WriteLines, as it were.


              So, let's take a look at one possible refinement (I'm going to address points 1 and 2):



              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)

              while (true)

              double number1 = GetNumber();
              Console.Clear();
              Console.WriteLine(number1);
              Console.WriteLine();
              string action = GetAction();
              double number2 = GetNumber();
              Console.WriteLine(number2);
              double result = Perform(number1, action, number2);
              Console.Clear();
              Console.WriteLine(number1 + action + number2);
              Console.WriteLine();
              Console.WriteLine("= " + result);
              Console.Write("Press enter to calculate again: ");
              Console.ReadLine();
              Console.Clear();



              private static double GetNumber()

              double number;

              Console.Write("Number: ");
              while (!double.TryParse(Console.ReadLine(), out number))

              NumberInputError();


              return number;


              private static void NumberInputError()

              Console.Clear();
              Console.WriteLine();
              Console.WriteLine();
              Console.WriteLine("Wrong sort of input.");
              Console.Write("Enter a number: ");


              private static string GetAction()

              while (true)
              (action == "/")


              private static double Perform(double number1, string action, double number2)

              switch (action)

              case "+": return number1 + number2;
              case "-": return number1 - number2;
              case "*": return number1 * number2;
              case "/": return number1 / number2;
              default: throw new InvalidOperationException("False action input, choose between: / ; * ; - ; +");










              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 22 mins ago









              Jesse C. Slicer

              11.1k2739




              11.1k2739







              • 1




                Thank you very much! You illuminated me by using private static s. Now I know what to learn next and how to improve. THANK YOU VERY MUCH!
                – Betrax
                6 mins ago










              • Glad to help - hope to see more refinements and iterations along your journey.
                – Jesse C. Slicer
                5 mins ago












              • 1




                Thank you very much! You illuminated me by using private static s. Now I know what to learn next and how to improve. THANK YOU VERY MUCH!
                – Betrax
                6 mins ago










              • Glad to help - hope to see more refinements and iterations along your journey.
                – Jesse C. Slicer
                5 mins ago







              1




              1




              Thank you very much! You illuminated me by using private static s. Now I know what to learn next and how to improve. THANK YOU VERY MUCH!
              – Betrax
              6 mins ago




              Thank you very much! You illuminated me by using private static s. Now I know what to learn next and how to improve. THANK YOU VERY MUCH!
              – Betrax
              6 mins ago












              Glad to help - hope to see more refinements and iterations along your journey.
              – Jesse C. Slicer
              5 mins ago




              Glad to help - hope to see more refinements and iterations along your journey.
              – Jesse C. Slicer
              5 mins ago












              up vote
              2
              down vote













              I think your variant can be improved by reducing the number of code duplication.



              My var:



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

              namespace ConsoleApp1

              class Program

              static double Number1;
              static string Action;
              static double Number2;
              static double Answer;
              static void Main(string args)

              bool AppOn = true;

              while (AppOn != false)

              Console.WriteLine();
              Console.WriteLine();
              Console.Write("Number: ");

              Number1 = TryGetNumber();

              Console.Clear();
              Console.WriteLine(Number1);


              Action = TryGetAction();

              Console.Clear();
              Console.WriteLine(Number1 + Action);


              Number2 = TryGetNumber();

              Console.Clear();
              Console.WriteLine(Number1 + Action + Number2);


              switch (Action)

              case "*":
              Answer = Number1 * Number2;
              break;
              case "-":
              Answer = Number1 - Number2;
              break;
              case "+":
              Answer = Number1 + Number2;
              break;
              case "/":
              Answer = Number1 / Number2;
              break;


              Console.WriteLine();
              Console.WriteLine("= " + Answer);
              Console.Write("Press enter to calculate again or esc for exit: ");
              ConsoleKeyInfo keyInfo = Console.ReadKey();
              if (keyInfo.Key == ConsoleKey.Enter)

              AppOn = true;


              switch (keyInfo.Key)

              case ConsoleKey.Enter:
              AppOn = true;
              break;
              case ConsoleKey.Escape:
              AppOn = false;
              break;


              Console.Clear();




              public static double TryGetNumber()

              double resultNumber;

              while (!double.TryParse(Console.ReadLine(), out resultNumber))

              Console.Clear();
              Console.WriteLine();
              Console.WriteLine();
              Console.WriteLine("Wrong sort of input.");
              Console.Write("Enter a number: ");


              return resultNumber;


              public static string TryGetAction()

              Console.WriteLine();
              Console.WriteLine();
              Console.Write("Action: ");

              string result = "";
              bool success = false;

              while (success != true)

              return result;





              What i do? Step by step.



              1. Remove all goto operator. In C# and in some (many) others lang decided that goto operator is evil operator, because in small programs you cant see this hell, but on projects larger code will become so hard for read and write. And in any case you use methods. There are many reasons, I advise you to read about this.

              2. Remove dublicate.
                In your version a lot of code that was created by Ctrl + C, Ctrl + V. Usually try to move away from this, wrapping such pieces in the methods and using several times. Let me show:(same color indicates same piece)
                enter image description here

              Same pieces, but in my variant



              enter image description here



              1. My version seems to be the same volume , because I added a lot of indents and spaces, focusing on the steps and structuring the code.

              I use more things than in your version. I can answer your questions.






              share|improve this answer








              New contributor




              Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





















                up vote
                2
                down vote













                I think your variant can be improved by reducing the number of code duplication.



                My var:



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

                namespace ConsoleApp1

                class Program

                static double Number1;
                static string Action;
                static double Number2;
                static double Answer;
                static void Main(string args)

                bool AppOn = true;

                while (AppOn != false)

                Console.WriteLine();
                Console.WriteLine();
                Console.Write("Number: ");

                Number1 = TryGetNumber();

                Console.Clear();
                Console.WriteLine(Number1);


                Action = TryGetAction();

                Console.Clear();
                Console.WriteLine(Number1 + Action);


                Number2 = TryGetNumber();

                Console.Clear();
                Console.WriteLine(Number1 + Action + Number2);


                switch (Action)

                case "*":
                Answer = Number1 * Number2;
                break;
                case "-":
                Answer = Number1 - Number2;
                break;
                case "+":
                Answer = Number1 + Number2;
                break;
                case "/":
                Answer = Number1 / Number2;
                break;


                Console.WriteLine();
                Console.WriteLine("= " + Answer);
                Console.Write("Press enter to calculate again or esc for exit: ");
                ConsoleKeyInfo keyInfo = Console.ReadKey();
                if (keyInfo.Key == ConsoleKey.Enter)

                AppOn = true;


                switch (keyInfo.Key)

                case ConsoleKey.Enter:
                AppOn = true;
                break;
                case ConsoleKey.Escape:
                AppOn = false;
                break;


                Console.Clear();




                public static double TryGetNumber()

                double resultNumber;

                while (!double.TryParse(Console.ReadLine(), out resultNumber))

                Console.Clear();
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine("Wrong sort of input.");
                Console.Write("Enter a number: ");


                return resultNumber;


                public static string TryGetAction()

                Console.WriteLine();
                Console.WriteLine();
                Console.Write("Action: ");

                string result = "";
                bool success = false;

                while (success != true)

                return result;





                What i do? Step by step.



                1. Remove all goto operator. In C# and in some (many) others lang decided that goto operator is evil operator, because in small programs you cant see this hell, but on projects larger code will become so hard for read and write. And in any case you use methods. There are many reasons, I advise you to read about this.

                2. Remove dublicate.
                  In your version a lot of code that was created by Ctrl + C, Ctrl + V. Usually try to move away from this, wrapping such pieces in the methods and using several times. Let me show:(same color indicates same piece)
                  enter image description here

                Same pieces, but in my variant



                enter image description here



                1. My version seems to be the same volume , because I added a lot of indents and spaces, focusing on the steps and structuring the code.

                I use more things than in your version. I can answer your questions.






                share|improve this answer








                New contributor




                Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.



















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  I think your variant can be improved by reducing the number of code duplication.



                  My var:



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

                  namespace ConsoleApp1

                  class Program

                  static double Number1;
                  static string Action;
                  static double Number2;
                  static double Answer;
                  static void Main(string args)

                  bool AppOn = true;

                  while (AppOn != false)

                  Console.WriteLine();
                  Console.WriteLine();
                  Console.Write("Number: ");

                  Number1 = TryGetNumber();

                  Console.Clear();
                  Console.WriteLine(Number1);


                  Action = TryGetAction();

                  Console.Clear();
                  Console.WriteLine(Number1 + Action);


                  Number2 = TryGetNumber();

                  Console.Clear();
                  Console.WriteLine(Number1 + Action + Number2);


                  switch (Action)

                  case "*":
                  Answer = Number1 * Number2;
                  break;
                  case "-":
                  Answer = Number1 - Number2;
                  break;
                  case "+":
                  Answer = Number1 + Number2;
                  break;
                  case "/":
                  Answer = Number1 / Number2;
                  break;


                  Console.WriteLine();
                  Console.WriteLine("= " + Answer);
                  Console.Write("Press enter to calculate again or esc for exit: ");
                  ConsoleKeyInfo keyInfo = Console.ReadKey();
                  if (keyInfo.Key == ConsoleKey.Enter)

                  AppOn = true;


                  switch (keyInfo.Key)

                  case ConsoleKey.Enter:
                  AppOn = true;
                  break;
                  case ConsoleKey.Escape:
                  AppOn = false;
                  break;


                  Console.Clear();




                  public static double TryGetNumber()

                  double resultNumber;

                  while (!double.TryParse(Console.ReadLine(), out resultNumber))

                  Console.Clear();
                  Console.WriteLine();
                  Console.WriteLine();
                  Console.WriteLine("Wrong sort of input.");
                  Console.Write("Enter a number: ");


                  return resultNumber;


                  public static string TryGetAction()

                  Console.WriteLine();
                  Console.WriteLine();
                  Console.Write("Action: ");

                  string result = "";
                  bool success = false;

                  while (success != true)

                  return result;





                  What i do? Step by step.



                  1. Remove all goto operator. In C# and in some (many) others lang decided that goto operator is evil operator, because in small programs you cant see this hell, but on projects larger code will become so hard for read and write. And in any case you use methods. There are many reasons, I advise you to read about this.

                  2. Remove dublicate.
                    In your version a lot of code that was created by Ctrl + C, Ctrl + V. Usually try to move away from this, wrapping such pieces in the methods and using several times. Let me show:(same color indicates same piece)
                    enter image description here

                  Same pieces, but in my variant



                  enter image description here



                  1. My version seems to be the same volume , because I added a lot of indents and spaces, focusing on the steps and structuring the code.

                  I use more things than in your version. I can answer your questions.






                  share|improve this answer








                  New contributor




                  Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  I think your variant can be improved by reducing the number of code duplication.



                  My var:



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

                  namespace ConsoleApp1

                  class Program

                  static double Number1;
                  static string Action;
                  static double Number2;
                  static double Answer;
                  static void Main(string args)

                  bool AppOn = true;

                  while (AppOn != false)

                  Console.WriteLine();
                  Console.WriteLine();
                  Console.Write("Number: ");

                  Number1 = TryGetNumber();

                  Console.Clear();
                  Console.WriteLine(Number1);


                  Action = TryGetAction();

                  Console.Clear();
                  Console.WriteLine(Number1 + Action);


                  Number2 = TryGetNumber();

                  Console.Clear();
                  Console.WriteLine(Number1 + Action + Number2);


                  switch (Action)

                  case "*":
                  Answer = Number1 * Number2;
                  break;
                  case "-":
                  Answer = Number1 - Number2;
                  break;
                  case "+":
                  Answer = Number1 + Number2;
                  break;
                  case "/":
                  Answer = Number1 / Number2;
                  break;


                  Console.WriteLine();
                  Console.WriteLine("= " + Answer);
                  Console.Write("Press enter to calculate again or esc for exit: ");
                  ConsoleKeyInfo keyInfo = Console.ReadKey();
                  if (keyInfo.Key == ConsoleKey.Enter)

                  AppOn = true;


                  switch (keyInfo.Key)

                  case ConsoleKey.Enter:
                  AppOn = true;
                  break;
                  case ConsoleKey.Escape:
                  AppOn = false;
                  break;


                  Console.Clear();




                  public static double TryGetNumber()

                  double resultNumber;

                  while (!double.TryParse(Console.ReadLine(), out resultNumber))

                  Console.Clear();
                  Console.WriteLine();
                  Console.WriteLine();
                  Console.WriteLine("Wrong sort of input.");
                  Console.Write("Enter a number: ");


                  return resultNumber;


                  public static string TryGetAction()

                  Console.WriteLine();
                  Console.WriteLine();
                  Console.Write("Action: ");

                  string result = "";
                  bool success = false;

                  while (success != true)

                  return result;





                  What i do? Step by step.



                  1. Remove all goto operator. In C# and in some (many) others lang decided that goto operator is evil operator, because in small programs you cant see this hell, but on projects larger code will become so hard for read and write. And in any case you use methods. There are many reasons, I advise you to read about this.

                  2. Remove dublicate.
                    In your version a lot of code that was created by Ctrl + C, Ctrl + V. Usually try to move away from this, wrapping such pieces in the methods and using several times. Let me show:(same color indicates same piece)
                    enter image description here

                  Same pieces, but in my variant



                  enter image description here



                  1. My version seems to be the same volume , because I added a lot of indents and spaces, focusing on the steps and structuring the code.

                  I use more things than in your version. I can answer your questions.







                  share|improve this answer








                  New contributor




                  Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 11 mins ago









                  Arantler

                  1213




                  1213




                  New contributor




                  Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Arantler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.




















                      up vote
                      1
                      down vote













                      You should not be repeating. Put it below the the final else.



                      while (!double.TryParse(Console.ReadLine(), out Number2))





                      share|improve this answer
























                        up vote
                        1
                        down vote













                        You should not be repeating. Put it below the the final else.



                        while (!double.TryParse(Console.ReadLine(), out Number2))





                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          You should not be repeating. Put it below the the final else.



                          while (!double.TryParse(Console.ReadLine(), out Number2))





                          share|improve this answer












                          You should not be repeating. Put it below the the final else.



                          while (!double.TryParse(Console.ReadLine(), out Number2))






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 1 hour ago









                          paparazzo

                          4,8921733




                          4,8921733




















                              Betrax is a new contributor. Be nice, and check out our Code of Conduct.









                               

                              draft saved


                              draft discarded


















                              Betrax is a new contributor. Be nice, and check out our Code of Conduct.












                              Betrax is a new contributor. Be nice, and check out our Code of Conduct.











                              Betrax is a new contributor. Be nice, and check out our Code of Conduct.













                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f205906%2fconsole-calculator-for-2-numbers-at-a-time%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              Installing NextGIS Connect into QGIS 3?

                              One-line joke