Divide if not zero (Using else) Learn programming C# Sharp

Lesson:

Flow Control


Exercise:

Divide if not zero (Using else) 20


Objetive:

Create a version of the previous program, using "else"


Code:

using System;
public class exercise18
{
    public static void Main()
    {
        int number1, number2;

        Console.Write("Enter the first number:");
        number1 = Convert.ToInt32(Console.ReadLine());
        Console.Write("Enter the second number:");
        number2 = Convert.ToInt32(Console.ReadLine());

        if (number2 != 0)
        {
            Console.WriteLine("The result for {0} / {1} is {2}",
            number1, number2, number1 / number2);
        }
        else
            Console.WriteLine("No result");
    }
}