0
Countdown app
Hello, i have a problem with my code , i think im a little close to solve because 2 test case’s are correct ,but I didn’t mange to know the problem i have with the other test cases. I’d be thankful if anyone helped #include <iostream> using namespace std; int main() { int n; cin >> n; //your code goes here if( n % 5 ==0 ) cout<<"Beep"<<endl; do{ cout << n << endl; n--; } while (n > 0);{ } return 0; }
7 Réponses
+ 1
Shahad
What if n is 10 and why there is semicolon (;) after while loop?
When number is multiple of 5, print Beep
+ 1
I added a semicolon because when i didnt add it i got an error
+ 1
Shahad
You can use a for loop, with if as an exception
for( int i = n; i>=1; i--){
cout << i << endl;
if (i%5==0){ cout<< "Beep";}
}
return 0;
+ 1
A little advice too, before posting a question try to search it first. The below is a same question with other solving techniques.
Your thread might marked for deletion since its repeated.
https://www.sololearn.com/Discuss/2619758/?ref=app
+ 1
Shahad
Yes there would be error but there should not be opening curly braces { after semicolon (;)
Correct syntax of do while loop is:
do {
//Statement
} while(condition);
0
Put if condition inside loop
0
Your code is correct overall