+ 1

What did i do wrong?

You need to make a countdown to 1. After numbers which multiple of five you need to print "Beep". I made code, but cannot find a mistake #include <iostream> using namespace std; int main() { int n; cin >> n; while(n > 0) { if(n % 5 == 4) { cout << "Beep" << endl; } cout << n << endl; n--; } return 0; }

6th Nov 2022, 8:11 AM
Furchik
Furchik - avatar
10 Respuestas
+ 5
You need to print n first then print "Beep". // order you need. For beep check current number. You are checking privous number in loop.
6th Nov 2022, 9:02 AM
Jayakrishna 🇮🇳
6th Nov 2022, 8:49 AM
Furchik
Furchik - avatar
+ 2
simply write the number before the beep
6th Nov 2022, 8:59 AM
KrOW
KrOW - avatar
+ 2
Thank you! KrOW another time helped me. (Jayakrishna🇮🇳, thank you too )
6th Nov 2022, 5:56 PM
Furchik
Furchik - avatar
+ 1
the module % operator is the integer remainder of division then the remainder for a n multiple of 5 has to be 0, not 4
6th Nov 2022, 8:17 AM
KrOW
KrOW - avatar
+ 1
👍🏻
6th Nov 2022, 5:57 PM
KrOW
KrOW - avatar
0
I know it, but if I write ' == 0' the word 'Beep' writes before numbers multiple of five
6th Nov 2022, 8:47 AM
Furchik
Furchik - avatar
0
And my code completed four tests of five. I do not understand why
6th Nov 2022, 8:47 AM
Furchik
Furchik - avatar
0
👍
6th Nov 2022, 6:01 PM
Jayakrishna 🇮🇳
0
#include <iostream> using namespace std; int main() { int n; cin >> n; while(n > 0) { cout << n << endl; n--; if(n % 5 == 4) { } } cout<<"Beep"; return 0; }
8th Nov 2022, 4:23 AM
barna xhils
barna xhils - avatar