0

Countdown app

Hello, i have a problem with my code , i think im a little close to solve because 2 test case’s are correct ,but I didn’t mange to know the problem i have with the other test cases. I’d be thankful if anyone helped #include <iostream> using namespace std; int main() { int n; cin >> n; //your code goes here if( n % 5 ==0 ) cout<<"Beep"<<endl; do{ cout << n << endl; n--; } while (n > 0);{ } return 0; }

16th Dec 2021, 5:24 PM
Shahad
Shahad  - avatar
7 ответов
+ 1
Shahad What if n is 10 and why there is semicolon (;) after while loop? When number is multiple of 5, print Beep
16th Dec 2021, 5:41 PM
A͢J
A͢J - avatar
+ 1
I added a semicolon because when i didnt add it i got an error
16th Dec 2021, 5:43 PM
Shahad
Shahad  - avatar
+ 1
Shahad You can use a for loop, with if as an exception for( int i = n; i>=1; i--){ cout << i << endl; if (i%5==0){ cout<< "Beep";} } return 0;
16th Dec 2021, 6:00 PM
ShadowCipher
ShadowCipher - avatar
+ 1
A little advice too, before posting a question try to search it first. The below is a same question with other solving techniques. Your thread might marked for deletion since its repeated. https://www.sololearn.com/Discuss/2619758/?ref=app
16th Dec 2021, 6:05 PM
ShadowCipher
ShadowCipher - avatar
+ 1
Shahad Yes there would be error but there should not be opening curly braces { after semicolon (;) Correct syntax of do while loop is: do { //Statement } while(condition);
16th Dec 2021, 8:28 PM
A͢J
A͢J - avatar
0
Put if condition inside loop
17th Dec 2021, 8:39 PM
Umair lehri
0
Your code is correct overall
17th Dec 2021, 8:40 PM
Umair lehri