0
If I put the value of n equal to 15 and I want my output like this 15,beep,14,13,12,11,10,beep,9,8,7,6,5,beep,4,3,2,1
But i didn't not get what I want can anyone explain me https://code.sololearn.com/c52XM9lVj1Rw/?ref=app
4 Answers
+ 3
Also there is "Beep" not "beep"
+ 2
Oh yes , thank you
+ 1
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
//your code goes here
while(n>=1){
cout<<n<<",";
if(n%5==0){
cout<<"beep,";
}
n--;
}
return 0;
}
0
Hello. You have to place n-- after the "if" statement.
The reasoning is that:
1.You write the number
2.Check if the number % to 5 == 0
3.THEN decrease it.
The way you are doing it now is:
1.Write the number
2.Decrease it
3.Check if the number(-1, because you decreased it) % 5 == 0