Ask coding questions

← Back to all posts
Why is wrong?
dObbOb11 (1)
 // Addition
    if (mode.Equals("+")) {
      a = Convert.ToInt32(Console.ReadLine());
      b = Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("---------");
      Console.WriteLine(a + b);
      Console.WriteLine("---------");
    }
Comments
hotnewtop
OldWizard209 (1098)

You literally have to remove the last } which would make the code look like:

// Editor: https://replit.com/@dObbOb11/AnotherAcclaimedMaintenance



using System;

class MainClass {
  public static void Main (string[] args) {
    int a;
    string mode = Console.ReadLine();
    int b;

    // Addition
    if (mode.Equals("+")) {
      a = Convert.ToInt32(Console.ReadLine());
      b = Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("---------");
      Console.WriteLine(a + b);
      Console.WriteLine("---------");
    }

      // Subtraction
    if (mode.Equals("-"))  {
      a = Convert.ToInt32(Console.ReadLine());
      b = Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("---------");
      Console.WriteLine(a - b);
      Console.WriteLine("---------");
    }

      // Multiplication
    if (mode.Equals("*"))  {
      a = Convert.ToInt32(Console.ReadLine());
      b = Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("---------");
      Console.WriteLine(a * b);
      Console.WriteLine("---------");
    }

      // Division
    if (mode.Equals("/"))  {
      a = Convert.ToInt32(Console.ReadLine());
      b = Convert.ToInt32(Console.ReadLine());
      Console.WriteLine("---------");
      Console.WriteLine(a / b);
      Console.WriteLine("---------");
    }
      
      while (true) {

      }

    }
  }
19ecal (228)

You need to remove the last } and it works

dObbOb11 (1)

i thought you could only mark one as correct sorry

19ecal (228)

@dObbOb11 can you mark mine as correct plz

dObbOb11 (1)

I didn't even realise the error was there!

dObbOb11 (1)

that was easier than expected!