How do I add 1 to a variable?

Hello, title says all. Here is my code:

int timesPressed = 0;
int timesPressed +1 ;
if(timesPressed == 1){

The variable timesPressed relies on how many times a button is pressed. How would I add to that variable? Thanks.

int timesPressed = 0;

timesPressed += 1;


timesPressed = timesPressed + 1

Don't forget




which has a different return value but the same effect in this application. The former is actually more efficient in some cases, though the latter is more commonly used (e.g. C++).

timesPressed = timesPressed + 1;

is the most wordy but also makes it very obvious what's happening and therefore is the most beginner friendly.

Dude, for a question this basic about the language I always suggest that the OP google "C++ tutorial" and do the first few lessons, up until they start talking about classes.

Thanks all!