Need help with c++ countdown code | Sololearn: Learn to code for FREE!

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

c++

4/18/2021 4:45:35 PM

Mason

5 Answers

New Answer

+3

Mason Your code is right but there is Beep not beep. Check spelling. To avoid mistakes in future read problem carefully.

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

+2

Thanks for the help guys, didnt notice i misspelled Beep.

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

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