I posted a different question on this same program. My problem this time is how do I add to z only when y =6. It counts 1 full pallet but stops after that, which is what the code says. How do I get it to count every after that?
int x;
int y;
int z;
int t = 200;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
x = 0;
while (x < 5) {
x = x + 1;
Serial.println(x);
delay(t);
}
Serial.println("Box is full");
if(x == 5 ) {
y = y + 1;
Serial.print(y);
Serial.println(" Boxes");
Serial.println();
delay(t);
}
if (y == 6) {
z = z + 1;
Serial.print(z);
Serial.println(" Full pallets");
Serial.println();
delay(t);
}
}
That is the correct way. Is something not working the way you want?
After you added one to z, did you want to set y back to 0 so it would count up to 6 again? If you don't set y back to 0 it will count 7, 8, 9.... and never get back to 6.
I didn't quite understand your difficulty, but see if this modification I made to your code meets your need:
int x;
int y;
int z;
int t = 200;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
x = 0;
while (x < 5) {
x = x + 1;
Serial.println(x);
delay(t);
}
Serial.println("Box is full");
if(x == 5 ) {
y = y + 1;
Serial.print(y);
Serial.println(" Boxes");
Serial.println();
delay(t);
}
if (y%6 == 0) { // < < < < ---------------------------------------------
z = z + 1;
Serial.print(z);
Serial.println(" Full pallets");
Serial.println();
delay(t);
}
}
I need int z to continue counting. What do I need to change to accomplish that? I suppose int y would have to reset after it reaches 6, however I would like to keep the overall count of int y.
Hi,
if your problem was solved, do a kindness to everyone on the forum, especially to those who helped you. Write [Solved] before your topic title, so if someone searches and finds your topic, they'll know what the solution looks like.