Please help me , there is always same error. CS1513 } expected RRS feed

  • Question

  • using System;

    namespace PiCalcurator
        class Program
            static void Main(string[] args)
                float pi = 3.14159265359f;
                string start = "Výtejte v aplikaci, která ti pomůže počítat s Ludolfovým číslem (pí).";

                Console.WriteLine("Zadej instrukce: nasobeni, deleni, scitani, odcitani");

                string odpoved = Console.ReadLine();

                Console.WriteLine("Zadej druhe cislo");

                string cislo2 = Console.ReadLine();
                int cislo22 = Int32.Parse(cislo2);

                if (odpoved == "nasobeni") ;
                    Console.WriteLine("pi x {1} = {2}", pi, cislo2, pi * cislo22);
                else if (odpoved == "deleni") ;
    Saturday, March 4, 2017 8:37 PM


All replies

  • Remove the ";"


     if (odpoved == "nasobeni") ;

    Saturday, March 4, 2017 8:50 PM
  • That, pretty much.
    Any control structure governs over either the following block denoted by brakets, or until the next Semimkolon. Wichever comes first.

    It is a common beginner mistake to close if area too early with a semikolon. What the compiler sees is effectively:

                if (odpoved == "nasobeni") 
                  //This if does nothing until the next Semikolon.              
                ; //The if ends here
    //This block has nothing to do with the if. { Console.WriteLine("pi x {1} = {2}", pi, cislo2, pi * cislo22); }
    //The last if was a full block ago. Where does this else belong too? else if (odpoved == "deleni") //Again a rather short if ;

    Remember to mark helpfull answers as helpfull and close threads by marking answers.

    Saturday, March 4, 2017 8:57 PM