0

Need help with c++ countdown code

I’m currently working on the module “countdown” and am having trouble with the code. The problem asks that you create a counter that takes a users input and counts it down, beeping after multiples of 5. The code I have seems to do what is asked but some of the test cases say it doesn’t. I don’t want the answer to the module I just want to know what is wrong with the code so I can avoid the mistake in the future. Here is the code. https://code.sololearn.com/cZe0n8K3nrL9/?ref=app

18th Apr 2021, 4:45 PM
Mason
6 Respostas
+ 4
Mason Your code is right but there is Beep not beep. Check spelling. To avoid mistakes in future read problem carefully.
18th Apr 2021, 5:05 PM
A͢J
A͢J - avatar
+ 2
the question actually says to replace the multiple of 5 with the beep string In your code, you're just trying the print whole countdown first then you're checking to print out beep in the multiple of 5 on line 11. usually, the compiler excutes the code from 1 - n lines. the fix is to make an else statement and put the line 10 into the else statement. (don't try to put n-- variable into the if and else statement. otherwise it will result in infinite loop!) also, finally someone says not to post answers without explanation!
18th Apr 2021, 4:55 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
+ 2
Thanks for the help guys, didnt notice i misspelled Beep.
18th Apr 2021, 5:31 PM
Mason
+ 2
This worked for me #include <iostream> using namespace std; int main() { int n; cin >> n; //your code goes here while(n > 0){ cout<< n << endl; if(n % 5 == 0){ cout << "Beep" << endl; } n--; } return 0; }
19th Mar 2022, 9:00 PM
Olufikayomi Jetawo
0
//countdown #include <iostream> using namespace std; int main() { int n; cin >> n; while(n>=1) { cout<<n<<endl; if(n%5==0) cout<<"Beep"<<endl; n--; } return 0; } An example of Countdown
30th Aug 2021, 6:07 AM
Nafisa Mondal
Nafisa Mondal - avatar
0
//countdown #include <iostream> using namespace std; int main() { int n; cin >> n; while(n>=1) { cout<<n<<endl; if(n%5==0) cout<<"Beep"<<endl; n--; } return 0; } An example of Countdown
30th Aug 2021, 6:07 AM
Nafisa Mondal
Nafisa Mondal - avatar