0

Help me with loop

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

26th Dec 2021, 9:59 AM
Hafsa batool
5 odpowiedzi
+ 2
Please lin your code so we can help you! Hint: * get input (integer) * use a while loop to count down * output the current number of the iteration * on each iteration, check if the current number is a multiple of 5 using the % operator and an if-statement * if it is a multiple of 5, output Beep
26th Dec 2021, 10:04 AM
Lisa
Lisa - avatar
+ 2
if (i % 5 == 0) because you need to check the current number i in the for-loop it should be i > 0 instead of i > i, I think
26th Dec 2021, 10:13 AM
Lisa
Lisa - avatar
+ 1
using namespace std; int main() { int n; cin >> n; //your code goes here for(int i=n; i>1;i--){ cout<<i<<endl; if(n%5==0) cout<<"beep"; } return 0; }
26th Dec 2021, 10:08 AM
Hafsa batool
0
I have done this
26th Dec 2021, 10:08 AM
Hafsa batool
0
Lisa Thanks
26th Dec 2021, 10:16 AM
Hafsa batool