Menu
CoddyTech

復習 - if else

CoddyのC#ジャーニー「基礎」セクションの一部。レッスン 29/69。

challenge icon

チャレンジ

初心者

2つの数値 n1 と n2、および1文字の文字列 op を入力として受け取るコードが与えられています。

注意:ユーザーから入力を受け取る方法は次のレッスンで学びます。今は最初の3行には触れないでください。

 

op に指定可能な値は '+'、'-'、'/'、'*' です。

あなたのタスクは、以下の条件に基づいて変数 result を設定することです:

  • もし op が '+' なら、result に n1 + n2 を代入します。
  • もし op が '-' なら、result に n1 - n2 を代入します。
  • もし op が '/' なら、result に n1 / n2 を代入します。
  • もし op が '*' なら、result に n1 * n2 を代入します。

自分で試してみよう

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();
        
        // 以下にコードを記述してください
        double result = 0;
        
        
        
        Console.WriteLine(result);
    }
}

基礎のすべてのレッスン

自分で練習してみよう: C#オンラインコンパイラ