0
Please help me
I was doing a project in C++ and I don't know what is happening. My code is supposed to count down from the inputed number, and beep after a multiple of 5. It does this perfectly, but at the end it prints an enter, and this makes my code wrong. I can't figure out why this doesnt work, so I'm hoping that someone else can. Here is my code: #include <iostream> using namespace std; int main() { int n; cin >> n; int y=5; while (n>0) { int x=n%y; cout << n << endl; if (x<1) { cout<< "Beep \n"; n--; } else { n--; int x=n%y; } } return 0; }
2 Réponses
+ 2
That is not the problem, your code does not pass the test cases due to the extra space you print after "Beep". Remove that and everything should be fine.
+ 1
instead of the lines declaring x = n%y you could just evaulate n%y == 0 in your if statement. and yes also the space in “Beep_\n” needs to be removed