+ 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
6 Respuestas
0
I solved this using while loop.
Write if statement inside loop. if n % 5 == 0 print Beep else n
+ 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...
+ 1
Jayakrishna🇮🇳 , that is extremely helpful. Thank you 🙏🏽. I’m adding it to my notes.
+ 1
Tahiti🍷 You're welcome..
+ 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;
}
0
I’m having trouble understanding what’s causing the bug. 🐜😫🦟