Truble with a switch statment

I would like to us the SWITCH statment but can not get to work.

// Test  6-28-18

#include <UTFT.h>                       // include the UTFT graphics library
#define screenwidth 480                 // size of screen for this LCD              
#define screenheight 320                //                                           
#define graphsize 430                   // number of x datapoints (pixels) in graph  
#define graphheight 240                 // number of y pixels in graph               

extern uint8_t SmallFont[];             // small font array for display
extern uint8_t BigFont[];               // big font array

UTFT myGLCD(CTE32HR,38,39,40,41);       // data structure for the 3.2 inch LCD display

int scr_background;                      
int scr_foreground;                      
int scr_graphline;                      
int scr_axiscolor;  

char Title[] = "River Height";                // string for device name
char Version[] = "Version 1.0";                  // version
char logfilename[] = "RiverHeight.csv";             // and log file name

 
 
 int day=3;
 int month=2;
 int x=20;
 

 int u;
 int p;
 int t; 
 int Xlable0;
 int Xlable1;
 int Xlable2;
 int Xlable3;
 int Xlable4;
 
void setup() {        //======================================================================
  Serial.begin(19200);
  
   myGLCD.InitLCD(LANDSCAPE);                     // init the screen  
  
    scr_background = VGA_BLACK;
    scr_foreground = VGA_WHITE; 
    scr_graphline = VGA_RED;
    scr_axiscolor = VGA_AQUA;

   u = day;
   p=1;
 }  

void loop() {          //==========================================================================

  drawXlable();
 

  myGLCD.setColor(VGA_RED);
  myGLCD.drawLine( 1, 295 ,443 , 295 );
  delay(500);
  myGLCD.setColor(VGA_BLUE); 
  myGLCD.drawLine( 1, 295 ,443 , 295 );
 // delay(2200);
}  
//************************************************************************* 

void drawXlable(void) {
 myGLCD.setColor(VGA_WHITE);
  
// int day=3;
// int month=2;
// int x=20;
// Xlable = day;
// u = day;
// p=1;
 
 Serial.print(p);      //month
 Serial.print("-p    ");
 Serial.print(u);      //day
 Serial.print("-u ");
 Serial.print(t);      //day
 Serial.print("-t    ");
// delay(500);
Serial.print( Xlable0);
 Serial.print("-x0  "); 
 Serial.print( Xlable1);
 Serial.print("-x1  ");  
 Serial.print( Xlable2);
 Serial.print("-x2  ");  
 Serial.print( Xlable3);
 Serial.print("-x3  ");  
 Serial.print( Xlable4);
 Serial.println("-x4  ");  
  
  
 
  p=p+1;
  u=u+1;
 
     if(p==20){  //month
        p=1;
     }
      
     if(u==5){   //5 days 
      u=1;
      t=t+1; 
     }
 
     switch(t){                     //-------------------  switch  ---------------------------
        case0: Xlable0 = p;
        Serial.print( Xlable0);
        Serial.println("-x00  ");  
        break;
        case1: Xlable1 = p;
        Serial.print( Xlable1);
        Serial.println("-x11  ");  
        break;
        case2: Xlable1 = p;
        Serial.print( Xlable2);
        Serial.println("-x22  ");  
        break;
        case3: Xlable1 = p;
        Serial.print( Xlable3);
        Serial.println("-x33  ");  
        break;
        case4: Xlable1 = p;
        Serial.print( Xlable4);
        Serial.print("-x44  ");  
        break;
               
        Serial.print("n/a1  "); 
     }                                         //--------------------------------------------------------------------------
         
          
myGLCD.clrScr();
 test:
  if (x > 440){ x=20; 
    myGLCD.clrScr();
    }
  }

//***************************************************************************

void display_splash(void)                       // put up splash screen   ============================================
{
  myGLCD.setColor(VGA_RED);
  myGLCD.setBackColor(VGA_WHITE);  
  myGLCD.fillScr(VGA_RED);
  myGLCD.setColor(VGA_WHITE);
  myGLCD.fillRect(10, 10, screenwidth-10, screenheight-10);
  myGLCD.setColor(VGA_BLUE);
  myGLCD.setFont(BigFont);
  myGLCD.print(Title,CENTER,60);
  myGLCD.setFont(SmallFont);
  myGLCD.print(Version,CENTER,120);
  
 // delay(500);
  myGLCD.clrScr();
  return;
  }

The switch statement is a multi-way decision that tests whether an expression matches one of a number of constant integer values, and branches accordingly.

That is from K&R. Pay particular attention to the word 'constant' and have a look at your switch statement.

What's the problem? What does it do or not do that doesn't meet with your expectation?

It really looks like you don't need a switch case at all. It looks like you need to make the Xlable variables with numbers on them into an array. Anytime you catch yourself trying to put numbers on the end of variable names what you really want is an array.

If they are an array it reduces to this:

switch(t){                     //-------------------  switch  ---------------------------
        case0: Xlable0 = p;
        Serial.print( Xlable0);
        Serial.println("-x00  ");  
        break;
        case1: Xlable1 = p;
        Serial.print( Xlable1);
        Serial.println("-x11  ");  
        break;
        case2: Xlable1 = p;
        Serial.print( Xlable2);
        Serial.println("-x22  ");  
        break;
        case3: Xlable1 = p;
        Serial.print( Xlable3);
        Serial.println("-x33  ");  
        break;
        case4: Xlable1 = p;
        Serial.print( Xlable4);
        Serial.print("-x44  ");  
        break;
               
        Serial.print("n/a1  "); 
     }

Becomes|:

if(t == 0){
    Xlable[0] = p;
} else {
    Xlable[1] = p;
}
Serial.print(Xlable[t]);
Serial.print(" -x");
Serial.print(t);
Serial.print(t);
Serial.print(" ");

Although I'm betting you wanted something a little different. I fixed what you wrote, not what I think you want. You'll have to tell me what you want if you want it fixed to do what you want.

Sometimes reformatting your code to make it more readable helps. Try yo find a style that you're comfortable with as well as others (as when you seek assistance).

Take your first case

case0: Xlable0 = p; Serial.print( Xlable0); Serial.println("-x00 "); break;

If you reformat this

case0: Xlable0 = p; Serial.print( Xlable0); Serial.println("-x00 "); break;

Does anything jump out at you as being a bit not right?

You have to put a space between the 'case' keyword and the value you are comparing against. Otherwise it looks like a label that you never use.

Build options changed, rebuilding all
/Users/john/Documents/Arduino/sketch_may31a/sketch_may31a.ino: In function 'void drawXlable()':
/Users/john/Documents/Arduino/sketch_may31a/sketch_may31a.ino:114:1: warning: label 'case0' defined but not used [-Wunused-label]
 case0: Xlable0 = p;
 ^
/Users/john/Documents/Arduino/sketch_may31a/sketch_may31a.ino:118:1: warning: label 'case1' defined but not used [-Wunused-label]
 case1: Xlable1 = p;
 ^
/Users/john/Documents/Arduino/sketch_may31a/sketch_may31a.ino:122:1: warning: label 'case2' defined but not used [-Wunused-label]
 case2: Xlable1 = p;
 ^
/Users/john/Documents/Arduino/sketch_may31a/sketch_may31a.ino:126:1: warning: label 'case3' defined but not used [-Wunused-label]
 case3: Xlable1 = p;
 ^
/Users/john/Documents/Arduino/sketch_may31a/sketch_may31a.ino:130:1: warning: label 'case4' defined but not used [-Wunused-label]
 case4: Xlable1 = p;
 ^
/Users/john/Documents/Arduino/sketch_may31a/sketch_may31a.ino:141:1: warning: label 'test' defined but not used [-Wunused-label]
 test:
 ^
/Users/john/Documents/Arduino/libraries/UTFT/DefaultFonts.c:21:14: error: variable 'SmallFont' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 fontdatatype SmallFont[1144] PROGMEM={         
              ^
/Users/john/Documents/Arduino/libraries/UTFT/DefaultFonts.c:125:14: error: variable 'BigFont' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 fontdatatype BigFont[3044] PROGMEM={
              ^
/Users/john/Documents/Arduino/libraries/UTFT/DefaultFonts.c:234:14: error: variable 'SevenSegNumFont' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 fontdatatype SevenSegNumFont[2004] PROGMEM={
              ^
exit status 1
Error compiling for board Arduino/Genuino Uno.

This is just a "test" program. I’m trying to print out a graph that has 50 days of data on it. I would like the Xaxis Label to show the days in 5 day step. Also to have the days along the X axes change each time the date changes. I can do this with an IF statement, but thought a Switch statement would work better. The "problem is" I cannot get the switch statement to work for me. switch (t){ case0: Xlabel0 = p //witch is the first group of day along the Xaxis. The present day. 10 case1: Xlabel1 = p //witch is the second group of day along the Xaxis. 5 days from present 5 case2: Xlabel2 = p //witch is the third group of day along the Xaxis. 10 days from present 30 case3: Xlabel3 = p //witch is the fourth group of day along the Xaxis. 15 days from present 25 case4: Xlabel4 = p //witch is the fifth group of day along the Xaxis. 20 days from present 20 --------- and so on --- Case9: Xlabel9= p //witch is the tenth group of day along the Xaxis. 25 days from present 25 }

To print out on a 480x320 TFT LCD along the Xaxis: 10 5 30 25 20 15 10 5 30 25

Then when the present day changes to 11 change the Xaxis to new numbers 11 6 1 26 21 16 11 6 2 26

This graft is for River Height . It will take a reading every 3 hours for a total of eight reading in 24 hours. This program is one I found on the internet and changing it to what I needed. I have it all working except for the getting the Xaxis to update.

Even though John just 'gave away' the answer, without you even having to think about it, you still don't get it.

'case' is a keyword, not some arbitrary prefix to be attached to an unused label of your choice. Read the books on the use of a switch statement.

Make the changes (or don't) and see if your code still doesn't work. Repeating the problem is going to fix it.

He's still going round about Laura's house to get there. If he'd learn to use an array he wouldn't need the switch, just a single line of code.