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;
x++;
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.
Sign up to join this communityYou 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++;
}
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.