Skip to main content
            namespace Test
        {
    class Program
            {
            static void Main(string[] args)
            {
                int firstNum;
            int secondNum;   int secondNum;                   //Variables for equation
                string operation;
                int answer;

                Console.WriteLine("Hello, welcome to Alex's basic calculator!");
                Console.ReadLine();

                Console.Write("Enter the first number in your basic equation: ");
                firstNum = Convert.ToInt32(Console.ReadLine());                             
                
                //User input for equation
                Console.Write("Now enter your second number in the basic equation: ");
                secondNum = Convert.ToInt32(Console.ReadLine());
                Console.Write("Ok now enter your operation ( x , / , +, -) ");
                operation = Console.ReadLine();

                if (operation == "x")
                {
                   answer = firstNum * secondNum;
                   Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
                   Console.ReadLine();
                }
                else if (operation == "/")
                {
                   answer = firstNum / secondNum;
                   Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
                   Console.ReadLine();
                }                                                                           
                //Getting answers
                else if (operation == "+")
                {
                   answer = firstNum + secondNum;
                   Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
                   Console.ReadLine();
                }
                else if (operation == "-")
                {
                   answer = firstNum - secondNum;
                   Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
                   Console.ReadLine();
                }
                else
                {
                   Console.WriteLine("Sorry that is not correct format! Please restart!");     //Catch
                   Console.ReadLine();
                }
           }
     }
}
            namespace Test
            class Program
            {
            static void Main(string[] args)
            {
            int firstNum;
            int secondNum;                      //Variables for equation
            string operation;
            int answer;

            Console.WriteLine("Hello, welcome to Alex's basic calculator!");
            Console.ReadLine();

            Console.Write("Enter the first number in your basic equation: ");
            firstNum = Convert.ToInt32(Console.ReadLine());                             //User input for equation
            Console.Write("Now enter your second number in the basic equation: ");
            secondNum = Convert.ToInt32(Console.ReadLine());
            Console.Write("Ok now enter your operation ( x , / , +, -) ");
            operation = Console.ReadLine();

            if (operation == "x")
            {
                answer = firstNum * secondNum;
                Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else if (operation == "/")
            {
                answer = firstNum / secondNum;
                Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
                Console.ReadLine();
            }                                                                           //Getting answers
            else if (operation == "+")
            {
                answer = firstNum + secondNum;
                Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else if (operation == "-")
            {
                answer = firstNum - secondNum;
                Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Sorry that is not correct format! Please restart!");     //Catch
                Console.ReadLine();
            }
        }
    }
}
 namespace Test
 {
    class Program
    {
            static void Main(string[] args)
            {
                int firstNum;
                int secondNum;                   //Variables for equation
                string operation;
                int answer;

                Console.WriteLine("Hello, welcome to Alex's basic calculator!");
                Console.ReadLine();

                Console.Write("Enter the first number in your basic equation: ");
                firstNum = Convert.ToInt32(Console.ReadLine());                             
                
                //User input for equation
                Console.Write("Now enter your second number in the basic equation: ");
                secondNum = Convert.ToInt32(Console.ReadLine());
                Console.Write("Ok now enter your operation ( x , / , +, -) ");
                operation = Console.ReadLine();

                if (operation == "x")
                {
                   answer = firstNum * secondNum;
                   Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
                   Console.ReadLine();
                }
                else if (operation == "/")
                {
                   answer = firstNum / secondNum;
                   Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
                   Console.ReadLine();
                }                                                                           
                //Getting answers
                else if (operation == "+")
                {
                   answer = firstNum + secondNum;
                   Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
                   Console.ReadLine();
                }
                else if (operation == "-")
                {
                   answer = firstNum - secondNum;
                   Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
                   Console.ReadLine();
                }
                else
                {
                   Console.WriteLine("Sorry that is not correct format! Please restart!");     //Catch
                   Console.ReadLine();
                }
           }
     }
}
Tweeted twitter.com/StackCodeReview/status/740925603411529728
added 150 characters in body; edited tags; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

First Program (Simple Calculator)! Tips? Simple calculator in C#

Ok this is my first program ever.

It is a basic calculator where the user inputs two numbers, and an operation and the program makes it into an equation and gets the answer. For example, if the user enters number 2 number 3 and tells it to multiply, it will display the answer as 6. I just want to know how this could be improved.

Could I have used loops or more advanced procedures to get the same output? Here is the code:

            namespace Test
            class Program
            {
            static void Main(string[] args)
            {
            int firstNum;
            int secondNum;                      //Variables for equation
            string operation;
            int answer;

            Console.WriteLine("Hello, welcome to Alex's basic calculator!");
            Console.ReadLine();

            Console.Write("Enter the first number in your basic equation: ");
            firstNum = Convert.ToInt32(Console.ReadLine());                             //User input for equation
            Console.Write("Now enter your second number in the basic equation: ");
            secondNum = Convert.ToInt32(Console.ReadLine());
            Console.Write("Ok now enter your operation ( x , / , +, -) ");
            operation = Console.ReadLine();

            if (operation == "x")
            {
                answer = firstNum * secondNum;
                Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else if (operation == "/")
            {
                answer = firstNum / secondNum;
                Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
                Console.ReadLine();
            }                                                                           //Getting answers
            else if (operation == "+")
            {
                answer = firstNum + secondNum;
                Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else if (operation == "-")
            {
                answer = firstNum - secondNum;
                Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Sorry that is not correct format! Please restart!");     //Catch
                Console.ReadLine();
            }
        }
    }
}

}

First Program (Simple Calculator)! Tips?

Ok this is my first program ever.

It is a basic calculator where the user inputs two numbers, and an operation and the program makes it into an equation and gets the answer. For example if the user enters number 2 number 3 and tells it to multiply it will display the answer as 6. I just want to know how this could be improved.

Could I have used loops or more advanced procedures to get the same output? Here is the code:

        namespace Test
        class Program
        {
        static void Main(string[] args)
        {
        int firstNum;
        int secondNum;                      //Variables for equation
        string operation;
        int answer;

        Console.WriteLine("Hello, welcome to Alex's basic calculator!");
        Console.ReadLine();

        Console.Write("Enter the first number in your basic equation: ");
        firstNum = Convert.ToInt32(Console.ReadLine());                             //User input for equation
        Console.Write("Now enter your second number in the basic equation: ");
        secondNum = Convert.ToInt32(Console.ReadLine());
        Console.Write("Ok now enter your operation ( x , / , +, -) ");
        operation = Console.ReadLine();

        if (operation == "x")
        {
            answer = firstNum * secondNum;
            Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
            Console.ReadLine();
        }
        else if (operation == "/")
        {
            answer = firstNum / secondNum;
            Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
            Console.ReadLine();
        }                                                                           //Getting answers
        else if (operation == "+")
        {
            answer = firstNum + secondNum;
            Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
            Console.ReadLine();
        }
        else if (operation == "-")
        {
            answer = firstNum - secondNum;
            Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
            Console.ReadLine();
        }
        else
        {
            Console.WriteLine("Sorry that is not correct format! Please restart!");     //Catch
            Console.ReadLine();
        }
    }
}

}

Simple calculator in C#

It is a basic calculator where the user inputs two numbers, and an operation and the program makes it into an equation and gets the answer. For example, if the user enters number 2 number 3 and tells it to multiply, it will display the answer as 6. I just want to know how this could be improved.

Could I have used loops or more advanced procedures to get the same output?

            namespace Test
            class Program
            {
            static void Main(string[] args)
            {
            int firstNum;
            int secondNum;                      //Variables for equation
            string operation;
            int answer;

            Console.WriteLine("Hello, welcome to Alex's basic calculator!");
            Console.ReadLine();

            Console.Write("Enter the first number in your basic equation: ");
            firstNum = Convert.ToInt32(Console.ReadLine());                             //User input for equation
            Console.Write("Now enter your second number in the basic equation: ");
            secondNum = Convert.ToInt32(Console.ReadLine());
            Console.Write("Ok now enter your operation ( x , / , +, -) ");
            operation = Console.ReadLine();

            if (operation == "x")
            {
                answer = firstNum * secondNum;
                Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else if (operation == "/")
            {
                answer = firstNum / secondNum;
                Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
                Console.ReadLine();
            }                                                                           //Getting answers
            else if (operation == "+")
            {
                answer = firstNum + secondNum;
                Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else if (operation == "-")
            {
                answer = firstNum - secondNum;
                Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Sorry that is not correct format! Please restart!");     //Catch
                Console.ReadLine();
            }
        }
    }
}
Source Link
Alex
  • 61
  • 1
  • 1
  • 2

First Program (Simple Calculator)! Tips?

Ok this is my first program ever.

It is a basic calculator where the user inputs two numbers, and an operation and the program makes it into an equation and gets the answer. For example if the user enters number 2 number 3 and tells it to multiply it will display the answer as 6. I just want to know how this could be improved.

Could I have used loops or more advanced procedures to get the same output? Here is the code:

        namespace Test
        class Program
        {
        static void Main(string[] args)
        {
        int firstNum;
        int secondNum;                      //Variables for equation
        string operation;
        int answer;

        Console.WriteLine("Hello, welcome to Alex's basic calculator!");
        Console.ReadLine();

        Console.Write("Enter the first number in your basic equation: ");
        firstNum = Convert.ToInt32(Console.ReadLine());                             //User input for equation
        Console.Write("Now enter your second number in the basic equation: ");
        secondNum = Convert.ToInt32(Console.ReadLine());
        Console.Write("Ok now enter your operation ( x , / , +, -) ");
        operation = Console.ReadLine();

        if (operation == "x")
        {
            answer = firstNum * secondNum;
            Console.WriteLine(firstNum + " x " + secondNum + " = " + answer);
            Console.ReadLine();
        }
        else if (operation == "/")
        {
            answer = firstNum / secondNum;
            Console.WriteLine(firstNum + " / " + secondNum + " = " + answer);
            Console.ReadLine();
        }                                                                           //Getting answers
        else if (operation == "+")
        {
            answer = firstNum + secondNum;
            Console.WriteLine(firstNum + " + " + secondNum + " = " + answer);
            Console.ReadLine();
        }
        else if (operation == "-")
        {
            answer = firstNum - secondNum;
            Console.WriteLine(firstNum + " - " + secondNum + " = " + answer);
            Console.ReadLine();
        }
        else
        {
            Console.WriteLine("Sorry that is not correct format! Please restart!");     //Catch
            Console.ReadLine();
        }
    }
}

}