This question is from C++ assignment please help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

This question is from C++ assignment please help

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".

22nd Nov 2020, 6:34 PM
Aditya Raj
Aditya Raj - avatar
11 Answers
+ 15
#include <iostream> using namespace std; int main() { int n; cin>>n; for (int a = n; a >0; a--) { cout << a << endl; if(a%5==0) { cout<<"Beep"<<endl; } } return 0; }
25th Nov 2020, 8:53 AM
AJAYKUMAR S
AJAYKUMAR S - avatar
+ 7
Hi! Here is what I made to solve this: #include <iostream> using namespace std; int main() { int b; cin>>b; for(int a=b;a>=1;a--) { cout<<a<<endl; while (a%5==0) { cout<<"Beep"<<endl<<a-1<<endl; a=a-1; } } return 0; } 100% works. I Hope it helped.
29th May 2021, 3:50 AM
Diyaan Bhat
Diyaan Bhat - avatar
+ 4
#include <iostream> using namespace std; int main() { int n; cin >> n; //your code goes here do { cout <<n <<endl; if (n%5==0){ cout <<"Beep"<<endl; } n--; } while (n >0); return 0;
29th Aug 2021, 12:10 PM
Aman Raj
0
Already tried , still asking for right ans
22nd Nov 2020, 6:53 PM
Aditya Raj
Aditya Raj - avatar
0
this works #include <iostream> using namespace std; int main() { int n; cin >> n; int a = n++; for (a=n; a--;) if (a>0) {cout << a << endl; if (a%5==0 && a>0) {cout << "Beep" << endl; } } return 0; }
20th Jan 2021, 11:44 AM
Matias Penttilä
Matias Penttilä - avatar
0
Can we do it using while loop
23rd Jan 2021, 8:31 AM
Hrishi Doshi
Hrishi Doshi - avatar
0
This is indeed possible with the while loop, this is the simplest I could get using a while loop with everything that has been taught up to this point. Added explanations just incase anyone later on still needs help, hope it's useful :) /* Countdown with a while loop */ int n; // this will be the user input cin >> n; // this takes the user input while (n >= 1) { /*the while loop starts here and checks if it is bigger or equal to 1* and if it is then it executes loop */ cout << n << endl; // this prints the current number and ends line if (n % 5 == 0) { /*in the condition brackets, the modulus operator is used to check if n divided by 5 has a remainder, if it does not, then it is indeed a multiple of 5 */ cout << "Beep" << endl; // if it is a multiple of 5, then it will print "Beep", if not, it will just skip the whole if operator } n = n - 1; // this just subtracts 1 from the current number to countdown by 1 }
20th Mar 2021, 7:29 PM
Johan Van Loggerenberg
Johan Van Loggerenberg - avatar
0
#include <iostream> using namespace std; int main() { int n,i; cin>>n; if(n<=4){ while(n<=0) { cout<<"n"; n--; } } for(i=n;i>0;i--) { cout<<i; if(i%5){ cout<<"\n"; } else{ cout<<"\nBeep\n"; } } return 0; }
15th Jun 2021, 11:37 AM
Comp_sy_02_Yash Bhosale
Comp_sy_02_Yash Bhosale - avatar
0
#include <iostream> using namespace std; int main() { int n; cin >> n; for(;n>0;n--){ cout<<n<<endl; if(n%5==0) {cout<<"Beep"<<endl;} } return 0; }
28th Aug 2022, 9:15 PM
omar mabsout
omar mabsout - avatar
0
#include <iostream> using namespace std; int main() { int n; cin >> n; for (int a=n;a>0;a--){ cout<<a<<endl; while(a%5==0) { cout<<"beep"<<endl<<a-1<<endl; a=a-1; } } return 0; } Why it is not right? Every output is right…
18th Sep 2022, 5:03 AM
Michal
Michal - avatar
- 4
I am beginner in the programation and dont speak very good english but if you are a beginner i recommend a lenguaje more easy
22nd Nov 2020, 6:38 PM
Hi I Am Noob :)
Hi I Am Noob :) - avatar