So i was trying to do "the countdown" activity and my code doesnt work. Can anyone help me out? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

So i was trying to do "the countdown" activity and my code doesnt work. Can anyone help me out?

#include <iostream> using namespace std; int main() { int n; int unimp=69420; cin >> n; while (n<unimp); { cout<<n--<<endl; } if (n=n*5) { cout<<"Beep"<<endl; } return 0; } Whats wrong with it?

7th Apr 2022, 9:31 AM
Screecher
Screecher - avatar
6 Answers
+ 1
#include <iostream> using namespace std; int main() { int n; int unimp=73936; cin>> n; while (n<unimp) //why you need this? while (n>0) { cout<<n<< endl; if (n%5==0) cout<<"Beep"<< endl; n-- ; // update after all print for next check } return 0; } // update n after printing.
8th Apr 2022, 12:21 PM
Jayakrishna 🇮🇳
+ 3
Remove semicolon after while( ) //; here use == instead of = in if block, and you may need it in loop.. I think. It's out side of loop currently..
7th Apr 2022, 9:39 AM
Jayakrishna 🇮🇳
+ 2
Yes it worked! Thank you so much!!
8th Apr 2022, 12:24 PM
Screecher
Screecher - avatar
+ 1
Used as a comparison, (n==n*5) would be false for all n except zero. I think you are trying to determine whether n is a multiple of 5. In that case, use the modulo operator, %. Modulo calculates the remainder of a division. If the remainder is zero, then the divisor is an even multiple. For example, 15/5 is 3 with remainder 0 (evenly divisible); whereas 19/5 is 3 with remainder 4 (not evenly divisible) if (n%5==0) { ...
8th Apr 2022, 7:22 AM
Brian
Brian - avatar
+ 1
#include <iostream> using namespace std; //you missed to add std here int main() { int n; int unimp=73936; cin>> n; while (n<unimp) //why you need this? while (n!=0) { cout<<n--<< endl; if (n%5==0) cout<<"Beep"<< endl; } return 0; } //Screecher check this code and if not work, then add your expected output.... hope it helps..
8th Apr 2022, 12:07 PM
Jayakrishna 🇮🇳
+ 1
You're welcome..
8th Apr 2022, 12:33 PM
Jayakrishna 🇮🇳