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; }
11 Answers
+ 3
while(n>=1){
cout << n << endl;
if(!(n%5)){
cout <<"Beep"<< endl;
}
n--;
}
+ 1
Ohh I see ..thanks Vasiliy
0
what is to be fixed ?
0
It's suppose to count down from an input 'n'
And output "beep" whenever it encounters multiples of 5
0
Vasiliy
Is it ? Didn't know
Thanks Vasiliy ..and now ?
0
I am glad that we understood each other and delete my remark.
0
But you are not getting away with one thanks âșïž
Comment on the errors in your code.
0
Vasiliy haha followed u as well
Alright
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?
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
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".