What is the error in it?? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
0

What is the error in it??

include <iostream> using namespace std; int main() { int n; cin >> n; int i; for(i=0;n>=1;--n ) { if(n%5==0) { cout << "Beep"; continue; } else { cout << n; } } //your code goes here return 0; } Question is: 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

2nd Jul 2021, 4:58 AM
Shahir
Shahir - avatar
4 Respuestas
+ 2
Shaik.Shahir First print number then print Beep if number is divisible by 5 and also no need to use continue. cout << n << endl; if (n % 5 == 0) cout << "Beep" << endl;
2nd Jul 2021, 5:04 AM
A͢J
A͢J - avatar
+ 2
Shaik.Shahir Check your for loop also. It should be for (i = n; i >= 1; i--) ------- for (i = n; i >= 1; i--) { cout << i << endl; if (i % 5 == 0) cout << "Beep" << endl; }
2nd Jul 2021, 5:07 AM
A͢J
A͢J - avatar
+ 1
Why are you posting C++ code and the tag is pointed to Python?🤔 int n; cin >> n; for(; n>=1; --n) { if(n%5==0) { cout << "Beep\n"; } else { cout << n << endl; } }
2nd Jul 2021, 7:38 AM
Solo
Solo - avatar
- 1
Hooo! I forgot
2nd Jul 2021, 7:56 AM
Shahir
Shahir - avatar