cannot we declare int i in switch-case statement in c++

[b][red]This message was edited by the c_anands at 2002-2-28 23:45:29[/red][/b][hr]
I am required to initialise some variable in a switch case statement(I am using VC++ 6).But it gives me error that the variable cannot be initialised.And one more thing is if we use if else ladder then it is fine.Can anybody solve my problem?
Anand.


Comments

  • : [b][red]This message was edited by the c_anands at 2002-2-28 23:45:29[/red][/b][hr]
    : I am required to initialise some variable in a switch case statement(I am using VC++ 6).But it gives me error that the variable cannot be initialised.And one more thing is if we use if else ladder then it is fine.Can anybody solve my problem?
    : Anand.
    :
    :
    :

    hi,
    you can do that but after case statement you must open { and close after }.
  • [italic]
    : I am required to initialise some variable in a switch case statement(I am using VC++ 6).But it gives me error that the variable cannot be initialised.And one more thing is if we use if else ladder then it is fine.Can anybody solve my problem?
    [/italic]

    [code]
    [blue]case[/blue] blabla:
    [blue]int[/blue] i;
    i = 5;
    [blue]break[/blue];
    [/code]

    This works as well. Just don't put it in one line.

    ---
    [b]edx[/b] - Member of [blue][b]CodeForce[/b][/blue] (http://codeforce.d2g.com)

  • : [italic]
    : : I am required to initialise some variable in a switch case statement(I am using VC++ 6).But it gives me error that the variable cannot be initialised.And one more thing is if we use if else ladder then it is fine.Can anybody solve my problem?
    : [/italic]
    :
    : [code]
    : [blue]case[/blue] blabla:
    : [blue]int[/blue] i;
    : i = 5;
    : [blue]break[/blue];
    : [/code]
    :
    : This works as well. Just don't put it in one line.
    :
    : ---
    : [b]edx[/b] - Member of [blue][b]CodeForce[/b][/blue] (http://codeforce.d2g.com)
    :
    :

    Yes sir..This works..The problem for is that I was unable to instantiate a class in the case statement..And That was the main problem...
    But I got the solution.Thanx.
    Anand.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories