0
What's wrong with my Countdown Code in C++?
#include <iostream> using namespace std; int main() { int n; cin >> n; { while (n >= 1) { cout << n << endl; n = n-1; if (n % 5 == 0) { cout << "Beep" << endl; }}} return 0; } it's currently 1 second off the requirement, for example it says "Beep" after 11 instead of 10
1 Odpowiedź
+ 4
You can use n = n -1 or decrement(n--) outside if statement.
Also there is an extra "{}" before while loop
while (condition){
if (condition){
}
n = n-1;
}