Thursday , July 7 2022
Home / C# / C# – More on arrays, loops and conditionals (Part 1)

C# – More on arrays, loops and conditionals (Part 1)

In this video we will revise what we have learned in our past videos.

  1. Making variables
  2. Taking inputs
  3. Loops
  4. Arrays
  5. Conditionals and switch cases

We will use these to achieve 2 tasks:

  1. Calculator
  2. 3 x 3 matrix using 2D arrays.

I have broken the video in 2 parts to not make it too long for you guys.

Part 1:

Code for the calculator:
Put this under static void main() line

double answer = 0;

Console.Write("Type first number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Type first number: ");
double num2 = Convert.ToDouble(Console.ReadLine());
Console.Write("Select an option: 1. Addition, 2. Subtraction, 3. Multiplication, 4. Division");
int selection = Convert.ToInt32(Console.ReadLine());

switch (selection) {
    case 1:
        answer = num1 + num2;
    case 2:
        answer = num1 - num2;
    case 3:
        answer = num1 * num2;
    case 4:
        answer = num1 / num2;
        Console.WriteLine("You chose wrong option");




About Waleed Baig

I am doing BS Computer Science. I have a passion to learn new technology and spread it. I am more enthusiastic about learning complex algorithm and making creative and efficient solution to a problem.

Check Also

C# 09 – Learning methods

In this tutorial we will learn What are methods? and How to create a method …

Leave a Reply

Your email address will not be published.