+ 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 Answers
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. šš«š¦