 Countdown problem | Sololearn: Learn to code for FREE!

+2

# 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

+4

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; }

+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.

+3

ChaoticDawg thank you so much brother. It works for me. I'll suggest everyone to type"Beep" not"beep".

+1

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.

+1

Move n--; to the end of the while after the if block.

+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; }

+1

//Without modulo operator #include <iostream> using namespace std; int main() { int N; cin >> N; while ( N >= 1 ) { cout << N << endl; N--; if ( N==4 || N==9 || N==14) {cout<< "Beep"<< endl;} } return 0; }

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; }

0

In Code Blocks work perfectly and show exactly what should to show

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; }

0

I did like this but still now show exactly same as request

0

I did that and is the same

0

Yeah is possible to be a hidden charcter

0

#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; }

0

0

Visit here for proper solution :- https://code.sololearn.com/cA22022A6a25

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