0

It... Works?

I was having a hard time with the transportation challenge and started moving things around. Well I got it but I don't really understand what I did correctly. the last thing i did was swap chair and person on line 9. i know its an odd question but, why does my code work? #include <iostream> using namespace std; int main() { int person, chair, empty, bus; cin >> person; chair = 50; bus = person %50 - chair; cout << bus *-1; return 0; } Edit: to clarify I'm not great at math and mostly wondering why swapping person and chair fixed it. Also I feel like I I probably wasn't supposed to resort to *-1 to make it work. So Id also like feedback on my solution. Tell me why it's bad.

15th Apr 2021, 4:22 AM
Collin
Collin - avatar
4 Respostas
+ 2
#include <iostream> using namespace std; int main() { int person, bus; cin >> person; bus =50- person %50 ; cout << bus; return 0; } //I think so by seeing this code 👆. You will be comfortable with the logic and don't define variables which you don't use
15th Apr 2021, 5:24 AM
Atul [Inactive]
+ 1
Yes it's working
15th Apr 2021, 5:22 AM
Atul [Inactive]
+ 1
Oh so I was close the first time! I originally had chair %50 - person. I just had to move the %50. Thanks!
15th Apr 2021, 6:19 AM
Collin
Collin - avatar