Menu
Coddy logo textTech

Recap - If Else

Part of the Fundamentals section of Coddy's C# journey — lesson 29 of 69.

challenge icon

Challenge

Beginner

You are given a code which gets as input two numbers n1 and n2 and a single char string op.

Note: we will learn in next lessons how to get input from the user, currently just don't touch the three first lines.

 

The possible values for op are '+', '-', '/' and '*'

Your task is to set the variable result based on the conditions:

  • if op is '+', set result with n1 + n2.
  • if op is '-', set result with n1 - n2.
  • if op is '/', set result with n1 / n2.
  • if op is '*', set result with n1 * n2.

Try it yourself

using System;

public class Program {
    public static void Main(string[] args) {
        int n1 = int.Parse(Console.ReadLine());
        int n2 = int.Parse(Console.ReadLine());
        string op = Console.ReadLine();
        
        // Write your code below
        double result = 0;
        
        
        
        Console.WriteLine(result);
    }
}

All lessons in Fundamentals