+ 3

Countdown problem

I try to resolve the Countdown problem and I don't understand why complier from here give other result than Code Blocks.I check with 12 and 15 and in Code Blocks show me right

9th Dec 2020, 10:18 AM
Andrei Macovei
Andrei Macovei - avatar
27 odpowiedzi
+ 10
This code works and passes all tests for me. If it's not working for you then you have some other issue. Maybe, a hidden character or something from coping and pasting. #include <iostream> using namespace std; int main() { int n; cin >> n; while ( n > 0) { cout << n << endl; if (n % 5 == 0) { cout << "Beep" << endl; } n--; } return 0; }
10th Dec 2020, 8:22 PM
ChaoticDawg
ChaoticDawg - avatar
+ 6
ChaoticDawg thank you so much brother. It works for me. I'll suggest everyone to type"Beep" not"beep".
13th May 2021, 9:13 PM
Aryan Singh Jadon
Aryan Singh Jadon - avatar
+ 3
Can you save your code to the playground and share a link to it here so that we may be able to help you and see what the issue with your code is.
9th Dec 2020, 10:24 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
#include <iostream> using namespace std; int main() { int n; cin >> n; //your code goes here for(int x = 1; n >= x;n--){ cout << n << endl; if(n % 5 == 0){ cout << "Beep" << endl; } } return 0; }
19th Dec 2020, 8:49 AM
aka :)
aka :) - avatar
+ 1
Ok,thank you
9th Dec 2020, 10:32 AM
Andrei Macovei
Andrei Macovei - avatar
+ 1
Any suggestion?
10th Dec 2020, 2:18 PM
Andrei Macovei
Andrei Macovei - avatar
+ 1
This code works and passes all the test cases #include <iostream> using namespace std; int main() { int n; cin >> n; for(int i=n;i>=1;i--) { if(i%5==0) { cout<<i<<endl; cout<<"Beep"<<endl; } else { cout<<i<<endl; } } return 0; }
27th Aug 2021, 12:05 PM
Ruchita Yadav
Ruchita Yadav - avatar
+ 1
Decided to use a do...while loop instead :D #include <iostream> using namespace std; int main() { int n; cin >> n; do { cout << n << endl; if (n % 5 == 0) { cout << "Beep" << endl; } n--; } while (n >= 1); return 0; }
5th Aug 2022, 2:13 PM
Iustin
0
#include <iostream> using namespace std; int main() { int n,a,i; cout<<"n=";cin >> n; a=n; for(i=1;i<=n;i++){ cout<<a<<endl; if(a%5==0) cout<<"Beep"<<endl; a--; } return 0; }
9th Dec 2020, 10:28 AM
Andrei Macovei
Andrei Macovei - avatar
0
In Code Blocks work perfectly and show exactly what should to show
9th Dec 2020, 10:29 AM
Andrei Macovei
Andrei Macovei - avatar
0
Remove the cout<<"n="; Try using a while loop while (n > 0) Then you could remove the other 2 variables and just use n for the output.
9th Dec 2020, 10:34 AM
ChaoticDawg
ChaoticDawg - avatar
0
#include <iostream> using namespace std; int main() { int n; cin >> n; while(n>0){ cout<<n<<endl; n--; if( n%5==0) cout<<"Beep"<<endl; } return 0; }
10th Dec 2020, 2:18 PM
Andrei Macovei
Andrei Macovei - avatar
0
I did like this but still now show exactly same as request
10th Dec 2020, 2:18 PM
Andrei Macovei
Andrei Macovei - avatar
0
Move n--; to the end of the while after the if block.
10th Dec 2020, 5:12 PM
ChaoticDawg
ChaoticDawg - avatar
0
I did that and is the same
10th Dec 2020, 7:54 PM
Andrei Macovei
Andrei Macovei - avatar
0
Thank you bro
10th Dec 2020, 8:23 PM
Andrei Macovei
Andrei Macovei - avatar
0
Yeah is possible to be a hidden charcter
10th Dec 2020, 8:24 PM
Andrei Macovei
Andrei Macovei - avatar
0
Or use a WHILE loop.
19th Dec 2020, 8:50 AM
aka :)
aka :) - avatar
0
Visit here for proper solution :- https://code.sololearn.com/cA22022A6a25
31st Jul 2021, 12:46 PM
RAJAT AGRAWAL
RAJAT AGRAWAL - avatar
0
#include <iostream> using namespace std; int main() { int n; cin >> n; while ( n > 0) { cout << n << endl; if (n % 5 == 0) { cout << "Beep" << endl; } n--; } return 0; } now it's working
19th Aug 2021, 6:13 PM
Swadhin Kumar
Swadhin Kumar - avatar