+ 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
27 Respostas
+ 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;
}
+ 6
ChaoticDawg thank you so much brother. It works for me. I'll suggest everyone to type"Beep" not"beep".
+ 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
#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;
}
+ 1
Ok,thank you
+ 1
Any suggestion?
+ 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
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;
}
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
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.
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
Move n--; to the end of the while after the if block.
0
I did that and is the same
0
Thank you bro
0
Yeah is possible to be a hidden charcter
0
Or use a WHILE loop.
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