crosses initalization of?

its my code but it doesnt work

#include <IRremote.h>
#include <IRremoteInt.h>
#include <IRremoteTools.h>
#include <SevSeg.h>


SevSeg sevseg;
int Time = 0; 
int Min = 0; 
int Sec = 0; 
int StartStopValue = 0;
int RecvPin = 11; 
IRrecv irrecv(RecvPin);
decode_results results;

void setup() {
  irrecv.enableIRIn();
  sevseg. Begin(0,0,1,2,3,4,5,6,7,8,9,10,13);
  sevseg. Brightness(90);
}

void loop() {
  // put your main code here, to run repeatedly:
  while(StartStopValue == 0) {
     switch(results.value) {      
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      
      if (irrecv.decode(&results)) {
      long int decCode = results.value;
      
      case 16724175: {
      Min = Min + 30;
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     }
      
     case 16718055: { 
      Min = Min + 10;
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     }
      
     case 16743045: {
      Min = Min + 5; 
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     }
     
     case 16716015: {
      Min = Min + 3;
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     }
     
     case 16726125: { 
      Min = Min + 1; 
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     }
     
     case 16734885: { 
      Sec = Sec + 30; 
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     } 
     
     case 16728765: {
      Sec = Sec + 10;
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     } 
     
     case 16730805: {
      Sec = Sec + 5;
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     } 
     
     case 16732845: {
      Sec = Sec + 1; 
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     }
      
     case 16738455: { 
      Min = 0; 
      Sec = 0;
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     }
      
     case 16761405: {
      StartStopValue = 1;
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     } 
     
     default: { 
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      break;
     }
     
    }
    
     if(Min > 99); {
      Min = 0;
     } 
     
     if(Sec > 59); {
      Sec = 0;
     }
     
     Time = Min * 100 + Sec;

     sevseg.NewNum(Time,2);
     sevseg.PrintOutput();
     if (irrecv.decode(&results)) {
     long int decCode =  results.value;
    }
   } 
  }
  while(StartStopValue == 1); { 
   if(Time % 100 != 0); { 
    Time = Time - 1;
    delay(1000);
    sevseg.NewNum(Time,(byte) 2);
    sevseg.PrintOutput();
    }
   if(Time % 100 == 0); { 
    Time = Time - 41; 
    delay(1000);
    sevseg.NewNum(Time,(byte) 2);
    sevseg.PrintOutput();
   }
   if(results.value = 16761405); {
    StartStopValue = 0; 
   }
   
   if(Time == 0); { 
    StartStopValue = 0; 
   }
  }
}

problem is "crosses initialization of ‘long int decCode’ " at 32nd line
(↓last line)

void loop() {
  // put your main code here, to run repeatedly:
  while(StartStopValue == 0) {
     switch(results.value) {      
      sevseg.NewNum(Time,2);
      sevseg.PrintOutput();
      
      if (irrecv.decode(&results)) {
      long int decCode = results.value;

what`s my wrong & how can fix it?

I do not know what the error message means and the error message is not properly posted.

That is a very strange switch/case statement. The lines after the switch statement should be in a case statement but are not. The if statement includes case statements but should not. I want to help you to correct the errors but I do not understand what was intended so I cannot help further.

Good Luck!

long int decode = results.value is a variable declaration. You have that line twice within the same function line 31 and line 132. You are declaring an already declared variable, that is what the compiler is complaining about. Lose the long int in front of line 132 or use a different variable name (that has not been declared already).

posted by vaj4088

That is a very strange switch/case statement.

I agree with that.

I don't think that declaring a variable inside of a switch block is legal, now that I think about it. I know for sure that you can't declare a variable in a case.

So, put in it where?

if (irrecv.decode(&results)); {
long int decCode = results.value;

I am kind of guessing here, but try removing the long int from the second declaration so it becomes an assignment not a declaration. I can't try it as I don't have the proper libraries installed.

Since reading Ray's post (scoping reminder), I realized that there is no duplicate definition as both declarations are in if statements so are local to the if block. So I don't know how to fix the error. Sorry for leading down the wrong path.

groundfungus: I don't think that declaring a variable inside of a switch block is legal, now that I think about it. I know for sure that you can't declare a variable in a case.

It's so often the things people are most sure of that are most un-true.... You absolutely can declare variables within a case. You simply have to use curly braces to enclose the case so the scope of the variable is restricted to that case, which is precisely the error the OP is seeing.

switch (x)
{
    case 0:
       int i = 1;  // this is not legal
       break;
    
    case 1:
    {
       int i = 1;  // this is perfectly legal
       break;
    }
}

Regards, Ray L.

I stand corrected and that is good to know.

TaeYeonKim: So, put in it where?

if (irrecv.decode(&results)); {
long int decCode = results.value;

Before the switch. I just encountered the same error message (and a whole lot more) when I accidentally had a variable declaration / initialisation as the first few lines directly after the switch :(

Remove the ; near the end of the ‘if’, from …

if (irrecv.decode(&results)); {
    long int decCode = results.value;

… to …

if (irrecv.decode(&results))
{
    long int decCode = results.value;

There are at least three 'if's and a 'while' like this.

I thought perhaps pointing out that instance would get the rest of the code reviewed for similar or other such instances.

EDIT: Note the code has another issue in that it has a code declared inside the switch but outside an 'case' statement.

lloyddean wrote (in part):

I thought perhaps pointing out that instance would get the rest of the code reviewed for similar or other such instances.

It should. I know that I would. I am certain that you would. However, I have seen cases on this forum in the past where that is not true. Sigh. :(

lloyddean wrote (in part):

Note the code has another issue in that it has a code declared inside the switch but outside an 'case' statement.

I already wrote

The lines after the switch statement should be in a case statement but are not

so I agree completely.

For fun abuse of the C/C++ switch statement, see "Duff's Device".