34 Answers
New AnswerYou 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
11/29/2020 6:28:55 AM
Krish Mohan34 Answers
New AnswerKrish Mohan n=--n is a totally funny and wrong stmt. --n means n=n-1 So replace n=--n with --n; in ur code and then its correct....
You can use a for loop too. Here's an example : for (int i=n; i > 0; i--) { cout << i << endl; if (i % 5 == 0) { cout << "Beep" << endl; } } It works just the same as Nasif Rahman's while loop.
#include <iostream> using namespace std; int main() { int n; cin >> n; do{ cout<<n; if(n%5==0) { cout<<"Beep"; } n--; } while(n>0); //your code goes here return 0; }
Learn Playing. Play Learning
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message