0

C++ , 21 code project. How do I fix it . I can't figure it out

#include <iostream> using namespace std; int main() { int n; cin >> n; while (n>=1){ cout <<n<<endl; n--; /*decrement after the if statement closes */ if(n%5){ //if(!(n%5)) cout <<"beep"<<endl; } } return 0; }

17th Oct 2021, 11:28 AM
Elias [101]
Elias [101] - avatar
11 Answers
+ 3
while(n>=1){ cout << n << endl; if(!(n%5)){ cout <<"Beep"<< endl; } n--; }
17th Oct 2021, 11:41 AM
Solo
Solo - avatar
+ 1
Ohh I see ..thanks Vasiliy
17th Oct 2021, 11:43 AM
Elias [101]
Elias [101] - avatar
0
what is to be fixed ?
17th Oct 2021, 11:32 AM
Jasy Fabiano
Jasy Fabiano - avatar
0
It's suppose to count down from an input 'n' And output "beep" whenever it encounters multiples of 5
17th Oct 2021, 11:37 AM
Elias [101]
Elias [101] - avatar
0
Vasiliy Is it ? Didn't know Thanks Vasiliy ..and now ?
17th Oct 2021, 12:59 PM
Elias [101]
Elias [101] - avatar
0
I am glad that we understood each other and delete my remark.
17th Oct 2021, 2:28 PM
Solo
Solo - avatar
0
But you are not getting away with one thanks â˜ș Comment on the errors in your code.
17th Oct 2021, 2:33 PM
Solo
Solo - avatar
0
Vasiliy haha followed u as well Alright
18th Oct 2021, 5:35 AM
Elias [101]
Elias [101] - avatar
0
No, that won't work. Why is it necessary to put an exclamation mark before the expression n%5, or how to write this condition differently?
18th Oct 2021, 8:27 AM
Solo
Solo - avatar
0
Vasiliy actually it worked I tried it. And it was ur idea remember ? If it's just n%5 . It will output "Beep" all the time the loop runs except for the multiples of five . So to reverse it we used "!" Right ? that's how I understood it
18th Oct 2021, 10:36 AM
Elias [101]
Elias [101] - avatar
0
to determine a multiple of 5, it is necessary that the condition is met under which the number divided by modulus is equal to zero, that is, if 15% 5 == 0 the condition is true, since 15% 5 = 0, but if the condition is written in abbreviated form if 15% 5, it is false , and we need to make it true, for this we put before the condition "!", which means "not" and reads like "If not false then true".
19th Oct 2021, 6:31 PM
Solo
Solo - avatar