Recap - If Else
Part of the Fundamentals section of Coddy's C# journey — lesson 29 of 69.
Challenge
BeginnerYou 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
opis'+', setresultwithn1 + n2. - if
opis'-', setresultwithn1 - n2. - if
opis'/', setresultwithn1 / n2. - if
opis'*', setresultwithn1 * 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
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic Shortcuts5Operators Part 2
Comparison OperatorsLogical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 36Decision Making
If StatementIf - ElseSwitch StatementTernary OperatorRecap - If ElseNested If - Else