Altering a variable inside an for/if statement

Hi all,

I'm just at the beginning of programming, so please forgive me if this question sounds dumb.

I'm trying to alter a variable inside a for/if loop. Unfortunately I can't get it to work. Maybe someone of you could give me a hint to the solution?

The Problem is with the variable "Tallyp1, Tallyp2, Tallyp3..."

I have this piece of code:

int Tallyp1 = 0;
int Tallyp2 = 0;
int Tallyp3...

for (int t = 0; t < 8; t++){
  if (AtemSwitcher.getTallyByIndexTallyFlags(t+1) == 1 | AtemSwitcher.getTallyByIndexTallyFlags(t+1) == 3 && (Tallyp(t+1)) == 0 ){

The error returned is that "'Tallyp' was not declared in this scope"
That is right because it has to be "Tallyp1, Tallyp2..."

It dowsn't seem to recognize the operation as part of the variable name. How do I alter this variable inside the for/if loop?

Sorry for my bad english - I don't know how to describe it better.

Thank you for your help!

Cheers

Andrew

Post all your code.
Use code tags.
Post all your error messages

That is right because it has to be "Tallyp1, Tallyp2..."

After you have posted your code I suspect that you need to read up on arrays.

Hi,

thanks for your quick answers.

The only thing that I need to know is how do I alter the variable name inside the for/if statement:

for (int t = 0; t < 8; t++){
  if (AtemSwitcher.getTallyByIndexTallyFlags(t+1) == 1 | AtemSwitcher.getTallyByIndexTallyFlags(t+1) == 3 && (Tallyp(t+1)) == 0 ){

How do I tell the Arduino to intepret (Tallyp(t+1)) as "Tallyp1" or "Tallyp2"...?

Thanks!

Cheers

Andreas

Please read these two posts:

How to use this forum - please read.
and
Read this before posting a programming question ...
You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button.

How do I tell the Arduino to intepret (Tallyp(t+1)) as "Tallyp1" or "Tallyp2"...?

You can't

You can, however, have an array of values with a common name and refer to them as
Tallyp[0], Tallyp[1], Tallyp[2] etc.

mindandvision:
The only thing that I need to know is how do I alter the variable name inside the for/if statement:

That is not possible.

Variable names are only used by the compiler and they are not uploaded to the Arduino and don't exist while the program is running.

Use an array for what you want. Something like

int Tallyp[4];  // a 4 element array indexed 0 to 3

then you can do Tallyp[t+1] =
assuming that t+1 evaluates to a valid index value

...R

Fantastic Robin,
and thank you UKHeliBob,

I will try to use an array for that!

Great helpful people here in the forum!

Cheers

Andreas