0

Please help with this code. Countdown (module project) in C++

#include <iostream> using namespace std; int main() { int n; cin >> n; do { cout<< n<< endl; if (n%5==0); cout<< n << endl; cout << "Beep" << endl; n--; } while (n>1); return 0; }

22nd Aug 2021, 10:37 AM
Shruti Munot
Shruti Munot - avatar
1 Answer
+ 3
All the statements that should be executed in case the condition of an if statement is true need to be enclosed in a block: if ( n % 5 == 0 ) { cout << "Beep" << endl; } As you can see, a semicolon is not necessary. Also, you don't need to repeat the current number, since it already has been printed before the conditional. Furthermore, the task wants you to print the countdown until one (inclusive), so you should change the condition of the loop to "n > 0" instead of "n > 1".
22nd Aug 2021, 11:14 AM
Shadow
Shadow - avatar