I can't figure out why x won't increment. here is the block of code. I already have y declared as the users input.

for (whatever reason) {

int x = 2;

int h = y - y + x;


2 Answers 2


You are declaring a local variable inside of a for loop. This will make the variable have the value of 2 everytime the loop is executed, hence making your increment at the end useless.

A solution to this is to declare x outside of the for loop. Example.

int x = 2;
for (int i = 0; i < 10; i++) 
     // do stuff


x is not in the for loop i is . you're declaring something but not using it. Go back and watch the walkthrough videos i week 2 that david malan does.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .