Calculator Program improvements I'm pretty new to programming and made a few programs so far. I recently made a Calculator program and I hope you guys could tell me what I could do to improve.
int firstNumber;
string sign;
int secondNumber;
int answer;

Console.WriteLine(&quot;Input Number:&quot;);
firstNumber = Convert.ToInt32(Console.ReadLine());
Console.Clear();

Console.WriteLine(&quot;Input Sign:&quot;);
sign = Console.ReadLine();
Console.Clear();

Console.WriteLine(&quot;Input Second Number:&quot;);
secondNumber = Convert.ToInt32(Console.ReadLine());
Console.Clear();

switch (sign)
{
    case &quot;+&quot;:
        answer = firstNumber + secondNumber;
        Console.WriteLine(answer);
        Console.ReadKey();
    break;
    case &quot;-&quot;:
        answer = firstNumber - secondNumber;
        Console.WriteLine(answer);
        Console.ReadKey();
    break;
    case &quot;*&quot;:
        answer = firstNumber * secondNumber;
        Console.WriteLine(answer);
        Console.ReadKey();
    break;
    case &quot;/&quot;:
        answer = firstNumber / secondNumber;
        Console.WriteLine(answer);
        Console.ReadKey();
    break;
    default:
        Console.WriteLine(&quot;Invalid Input&quot;);
    break;
}
In general
Whenever you try to implement an application try to use sentences to describe the desired behavior. After that ask yourself: &quot;Can it be further refined?&quot; If so, then write new sentences to detail your plan in a more fine-grained level.
Let me show you what I mean:
The view from 10 000 feet

The application can perform basic operations between two operands.

What can be further refined?

What does it mean basic operation?
What did we mean by two operands?

High-level view

The application can perform basic operations between two operands.

It allows addition, subtraction, multiplication and division.




User can provide two numbers and the desired operation.
The application will perform it on the user's behalf.


What can be further refined?

How can an user provide numbers?

Fine-grained problem decomposition

The application can perform basic operations between two operands.

It allows addition, subtraction, multiplication and division.




User can provide two numbers and the desired operation.

The application receives an input from the user then it perform a preliminary check.

If it is valid then it goes to the next statement.
If it is invalid then it ask the user again to provide a valid input.






The application will perform it on the user's behalf.


Let's put together the skeleton
Now, we can translate each sentence into instructions.
This problem decomposition also helps us to well-organize our code:
///&lt;summary&gt;
/// The application can perform basic operations between two operands.
///&lt;/summary&gt;
public static void Main()
{

}

///&lt;summary&gt;
/// User can provide two numbers and the desired operation.
///&lt;/summary&gt;
private static void AskForInputs()
{

}

///&lt;summary&gt;
/// The application receives an input from the user then it perform a preliminary check.
/// &lt;list type=&quot;bullet&quot;&gt;
/// &lt;item&gt;
/// &lt;description&gt;If it is valid then it goes to the next statement.&lt;/description&gt;
/// &lt;/item&gt;
/// &lt;item&gt;
/// &lt;description&gt;If it is invalid then it ask the user again to provide a valid input.&lt;/description&gt;
/// &lt;/item&gt;
/// &lt;/list&gt;
///&lt;/summary&gt;
///&lt;/summary&gt;
private static int AskForNumber()
{
    
}

///&lt;summary&gt;
/// The application receives an input from the user then it perform a preliminary check. &lt;para /&gt;
/// It allows addition, subtraction, multiplication and division.
///&lt;/summary&gt;
private static char AskForOperation()
{
    
}

///&lt;summary&gt;
/// The application will perform it on the users behalf.
///&lt;/summary&gt;
private static void PerformRequestedOperation()
{
    
}   

Observations about your implementation
The implementation is bit naive, because:

It does not handle those cases when the user provides malformed input

For example: instead of 3 (s)he provides three


It does not handle under- or overflow cases

For example: int.MaxValue + 100


It does not handle zero division case

For example: 100 / 0


It does not handle properly a division where the result is a floating number

For example: 10 / 3


etc.

In your switch statement you repeat the following two statement in each case:
Console.WriteLine(answer);
Console.ReadKey();

An alternative implementation could be:
switch (operation)
{
    case &quot;+&quot;:
        answer = firstNumber + secondNumber;
    break;
    case &quot;-&quot;:
        answer = firstNumber - secondNumber;
    break;
    case &quot;*&quot;:
        answer = firstNumber * secondNumber;
    break;
    case &quot;/&quot;:
        answer = firstNumber / secondNumber;
    break;
}
        
Console.WriteLine(answer);
Console.ReadKey();

This can be easily enhanced to include all the above validations as well:
switch (operation)
{
    case &quot;+&quot;:
        answer = PerformAddition(lhs, rhs);
    break;
    case &quot;-&quot;:
        answer = PerformSubtraction(lhs, rhs);
    break;
    case &quot;*&quot;:
        answer = PerformMultiplication(lhs, rhs);
    break;
    case &quot;/&quot;:
        answer = PerformDivision(lhs, rhs);
    break;
}
        
Console.WriteLine(answer);
Console.ReadKey();

Now as you can see we have introduced 4 new functions to abstract away the complexity to deal with different edge cases and the main flow remained easy to follow.