I'm having trouble with a loop. Basically I want to calculate a variable "i" such that it is less than or equal to a number typed in by the user, which i'm calling pickUpAtTime. As well, this variable i must satisfy the equation j=i*(3+1)+1 such that j is less than or equal to a number typed in by the user, which i'm calling totalToothpicks.
Oh yeah, and i'm trying to calculate the max i that will satisfy j<totalToothpicks, which is why i did the for loop.
So right now i've got:
EDIT:is supposed to be:Code:int j =0;
while(j<totalToothpicks ){
for(i=1; i<pickUpAtTime; i++)
j+=i*(3+1)+1;
}
but anyway that doesn't matter.Code:int j =0;
while(j<totalToothpicks ){
for(i=1; i<pickUpAtTime; i++)
j+=i*(pickUpAtTime+1)+1;
}
Why doesn't the for loop run, testing each instance of i=1 to i<pickUpAtTime, making sure that when each instance of i is plugged into the formula for j that j is less than totalToothpicks? Because for example, I'm getting answers like 13 for j when totalToothpicks is 12??
