Click here to Skip to main content
15,902,910 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I wrote my program and I got this error. " } expected".
after the If

C#
namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            double a;
            double b;
            double c;
            double x1;
            double x2;
            double formula;

            Console.WriteLine("Calculadora para la formula general");
            Console.WriteLine("inserte el valor de A");
            a = double.Parse(Console.ReadLine());
            Console.WriteLine("inserte el valor de B");
            b = double.Parse(Console.ReadLine());
            Console.WriteLine("inserte el valor de C");
            c = double.Parse(Console.ReadLine());
            formula = b * b - 4 - 0 * a * c;

            if (formula < 0) ;
            {
                Console.WriteLine("los resultados son imaginarios");
                formula = -formula;
            }
            
            else 
             Console.WriteLine("los resultados son reales");

            x1 = (-b + Math.Sqrt(formula)) / (2* a);
            x2 = (-b - Math.Sqrt(formula)) / (2 * a);

            Console.WriteLine("x1= " + x1);
            Console.WriteLine("x2= " + x2);
            Console.ReadKey();
            
        }
    }
}
Posted
Updated 22-Jan-16 18:56pm
v2
Comments
Sarath kumar.N 23-Jan-16 0:58am    
remove
BillWoodruff 23-Jan-16 1:34am    
What's happening that when you click on the no-compile error in Visual Studio you are not shown the line number where the error occurs and "taken there" ?

Visual Studio is your friend.

think about this

C#
if (formula < 0) ;


what is that semi-colon doing there ?
 
Share this answer
 
Remove semicolon from
C#
if(formula>0);
line
 
Share this answer
 
v2
C#
if (formula < 0) ;
{
    Console.WriteLine("los resultados son imaginarios");
    formula = -formula;
}

else
 Console.WriteLine("los resultados son reales");


The else condition needs a bracket.


C#
if (formula < 0) ;
{
    Console.WriteLine("los resultados son imaginarios");
    formula = -formula;
}

else {
 Console.WriteLine("los resultados son reales");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900