+ 1

Countdown (End of module project)

You need to make a countdown app. Given a number N as input, output numbers from N to 1 on separate lines. Also, when the current countdown number is a multiple of 5, the app should output "Beep". Sample Input: 12 Sample Output: 12 11 10 Beep 9 8 7 6 5 Beep 4 3 2 1 https://code.sololearn.com/cXEEucnUQGaD/?ref=app

2nd Mar 2021, 3:43 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
6 Answers
0
I solved this using while loop. Write if statement inside loop. if n % 5 == 0 print Beep else n
2nd Mar 2021, 5:14 AM
Hyperjones
Hyperjones - avatar
+ 3
if (n%5=0) this is not a proper statement, must be if( n%5==0 ) = is a equality operator , == is a comparision operator cout <<n, n-- << endl; this is also incomplete statement . Remove Comma cout<< n << n-- <<endl; and here you just need cout<< n-- <<endl; and bring if clouse into while loop to work as required... Hope it helps...
2nd Mar 2021, 8:49 AM
Jayakrishna šŸ‡®šŸ‡³
+ 1
JayakrishnašŸ‡®šŸ‡³ , that is extremely helpful. Thank you šŸ™šŸ½. Iā€™m adding it to my notes.
2nd Mar 2021, 6:10 PM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar
+ 1
TahitišŸ· You're welcome..
2nd Mar 2021, 6:14 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
// I did it with a for loop #include <iostream> using namespace std; int main() { int n; cin >> n; //your code goes here for(;n>=1;){ if(n%5==0 && n!=0) { cout << n << endl; cout << "Beep" << endl; n--; } else { cout<<n<<endl; n--; } } return 0; }
5th Feb 2022, 12:11 AM
William Alley
William Alley - avatar
0
Iā€™m having trouble understanding whatā€™s causing the bug. šŸœšŸ˜«šŸ¦Ÿ
2nd Mar 2021, 3:45 AM
TahitišŸŒCastillo
TahitišŸŒCastillo - avatar