- 4
c++ countdown program
Pls do solve and send anyone
17 Respostas
+ 5
vijayalakshmi T.G. check it
while(n>0){
if(n%5==0){
cout<<n<<endl<<"Beep"<<endl; /* it will first print the number(multiple of 5) then will print beep */
n--; /* decreasing by 1*/
}
else{
cout<<n<<endl; /* if not multiple of 5 then will print only that number*/
n--;
}
}
+ 5
Code: (Works)
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while(n>=1)
{
if(n%5==0){
cout<<n <<"Beep"<<"\n";}
else{
cout<<n;
}
n--;
}
return 0;
}
+ 4
int main() {
int n;
cin >> n;
while(n>=1)
{
if(n%5==0){
cout<<n <<"Beep"<<"\n";}
else{
cout<<n;
}
n--;
}
return 0;
}
+ 1
While(n>=1)
{
if(n=n%5);
Cout <<"Beep";
n--;
}
+ 1
= is an assignment operator use == instead of that
+ 1
Ok thank you
+ 1
These are some necessary changes that you should bring in your code
+ 1
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while (n>=1){
if (n%5==0){
cout << n << endl << "beep" << endl;}
else {
cout << n << endl;
}
n--;
}
return 0;
}
That works good, but i couldn't finish exercise because after number 1 programme still doing new blank line and app don't count it, anyone have some solution?
0
vijayalakshmi T.G. then show us your code .we can help you more accurately then .
0
Please post your try
0
// HI THERE!!
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while( n >= 1 ) {
if( n%5 == 0 ){
cout << n << '\n' << "Beep" << endl;
} else {
cout << n << '\n' << endl;
} n--;
}
return 0;
}
0
short and good!
#include <iostream>
using namespace std;
int main()
{int n;
cin >> n;
while(n>=1)
{if(n%5==0)
{cout<<n <<"Beep"<<"\n";}
else{cout<<n;}
n--;}
return 0;}
0
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while (n>0){
cout << n <<endl;
if (n%5==0){
cout << "Beep" << endl;
}
n--;
}
return 0;
}
0
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
//your code goes here
for (int i=n; i>0; i--){
cout << i <<endl;
if (i%5==0){
cout<<"Beep"<<endl;
}
}
return 0;
}
0
It seems there is only one way and when I see it I understand it and it is easy but how (from so many functions and variations) do I ever know I have to use this method exactly? I tried to do n>0 first after if and then modulus of 5 in else but I wouldn't have guessed to start with modulus after if and then do the main part in else phase. I would be natural to me to make bigger part after if and smaller part after else but here it is other way around. My problem seems to reoccur that I know the methods but don't know which one to pick and how to twist them for that specific way that I just don't see.
- 1
Please solve it yourself.
https://www.sololearn.com/discuss/333866/?ref=app
- 1
I had written the code but i don't know where i did mistake