0
How to make it appear every multiple of 5 "beep"
#include <iostream> using namespace std; int main() { int n; cin >> n; for(int x=n; x>0; x--) { cout<<x<<endl; if(x %5 == 0){ cout<<"beep"<<endl; } } }
5 Respuestas
+ 1
Lidandi Biki
The problem is, the "cout << n << endl;" is placed before the condition "if (x % 5 == 0)", hence, the number with the multiple of 5 will print first, before the word "beep"
Solution:
Place the "cout << x << endl;" to an else statement so that if a number is multiple of 5, it will print the "beep" without the number.
https://code.sololearn.com/cJI74MyH5o0X/?ref=app
+ 1
nicko's code is doesn't work, look for my code
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
for (int i=n;i>0;i--)
{
cout << i;
if(i % 5 == 0)
cout << "Beep";
}
return 0;
}
+ 1
Иван Чикyнов Sorry, but I dont think thats the right code, it is just the same with the previous one, you just removed the "endl".
+ 1
ok
0
Thanks everyone, this code is work