An UTC correction array

This is the first time I have ever tried an array... and I am only repeating the offending part of the program as it is too long (a successful marriage of a GPS sketch and a TFT Demo sketch both from Adafruit and working well. as is obvious tis is to simply convert UTC time from a GPS receiver to local (PDT) time, I'll worry about PST later as I need to get this working now before I can get to later

int hours = 0; //This works

These are the additions tonight. The only ones. If I change back the sketch to the point prior to this by changing the arrray reference to hours in the If statement it works
I've included my sorry code but I think it better to make something work before any other changes are made like moving most of this into functions so I can add some
more like temp, baro and hygro measurements as well as an X10 control function. Ultimately this will all be on a 32 PT SGC display by 4D Systems... One small thing at a time
I already have the others working except the X10 sketch. and I uploaded GPS_Time_Date_TFT_2_2_3

int hrs[24] = {16, 17, 18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; //these work
int hours = (GPS.hour); // GMT is + 7 Hrs so move it off to a - 12 hour offset
/* 24 hour to 12 jour AM/PM conversion */
if ( hrs[hours] >= 12) // AM/PM Test // access the hrs array Bombs and I am sure I made the error here

GPS_Time_Date_TFT_2_3:169: error: 'hrs' was not declared in this scope // Compiler error message

And here I'm Stuck as can't see how I made a scope error... I think the array is so simple that someone is going to ask about what I have been reading besides books on C
I do have an additional question, would it have been better to use an Enum array?

Doc

GPS_Time_Date_TFT_2_3.ino (10.4 KB)

Your hrs[] array is local to setup(), so is not in scope in loop().

I thought it could be declared a global variable and so placed it in setup with the other global vars so as to give it global scope... Wrong?
Can't sleep so I thought I'd ask for the solution to the issue...

Doc

You can also apply a time offset using modulo division, rather than an array.

char offset = 7; //Whatever time offset you need. In this case, +7 hours. This is anywhere between -11 and +12 normally.
hours += (24 - offset); //Apply the offset (adding to to keep positive)
hours %= 24; //Convert back to being within 24 hour range

Oh, to make something global, you don't put it in the setup. You put it outside any funtion. E.g.

byte thisByteIsGlobal;
void setup(){
   byte thisByteIsLocal;
}

void main(){
  thisByteIsGlobal =1; //This works as it is in a global scope.
  //thisByteIsLocal = 1; //This doesn't as it is only visible to setup();
}

Global variables have to be declared outside any function. Anything declared in setup() is local to setup().

Thank you for the help, someone else just posted another answer but I moved the array and it compiles and I can do the AM, PM thing Right and make it work as I use that to fix the date as well.

Doc

It's not just the array that is a problem - you have a number of variables declared in setup such as hours, days etc. They serve no purpose - they are local to setup and never used. You have avoided compiler errors by also declaring them in loop, but your understanding of how globals and locals work needs a little adjusting.

You are correct... I did the same to create vars for hours, minutes, days and month's and they worked... I remember thinking that these should go outside of setup... but then I went to bed and in the morning made the error... and then did it again. This is the reason why I keep my advice Strictly to the Electronics section where I an sometimes very busy... sometimes it is a 6 to 8 hour routine albeit with frequent breaks.
I really do enjoy myself however.
Thank You for the neat help. I couldn't figure out how to deal with the overflow and the negative numbers some of my attempts created

SDoc

WildBill thank you I realized a mistake and couldn't figure out why the vars were an issue for the compiler as the var's worked in the sketch execution. All will be corrected shortly, I Still have a great deal to learn...
But I bought my first Arduino (R3) in March.... and it has bitten me, I now own an Uno Clone a Mega2560 clone and two Pro Mini's and I am rally loving my retirement solely because of this forum and my "toys"
Thank you, TCWorld dxw00d and Wildbill for your generous help. I really appreciate it.

Doc