For and while loop count down
Hi, I have tired the count down app problem: Given a number N as input, output numbers from N to 1 on separate lines. Also, when the current countdown number is a multiple of 5, the app should output "Beep". I tried the for loop but "for" some reason the counter doesn't count down. it goes through the loop once and that is all. However when I used "while" loop it works fine, I am not sure why my "for" loop doesn't work as I expected it to work. #include <iostream> using namespace std; int main() { int n; cin >> n; for (int x = n; x >= 1; x=n-1 ) { cout << x << endl; if (x % 5 == 0) { cout << "Beep" << endl; } } /*while (n >=1) { cout << n <<endl; if (n % 5 == 0) { cout << "Beep" << endl; } n = n-1; }*/ return 0; }