0

Transportation-C++

I just finished the C++ course but have a really poor understanding. I'm trying to do the projects now but I'm really bad at them. Any help with this one? My attempt was: #include <iostream> #include <cstdlib> using namespace std; int main() { //your code goes here int a=50; int b; cin >> b; int sub; if (b<50) { sub=50-b; return sub; cout <<sub; } else if (b=a) { sub=0; return sub; } for (int sub=b; b > 50; b - 50){ return sub; } sub=abs(sub); cout << sub; return 0; }

10th Jan 2021, 10:48 PM
Lyra
Lyra - avatar
8 Réponses
+ 2
#include <iostream> using namespace std; int main() { int passengersNumber; cin >> passengersNumber; cout << 50 - passengersNumber % 50; return 0; }
11th Jan 2021, 12:19 AM
Vasile Eftodii
Vasile Eftodii - avatar
+ 1
Using the "return" clause will exit the current function, thus terminating your program!
11th Jan 2021, 12:21 AM
Vasile Eftodii
Vasile Eftodii - avatar
+ 1
A simple three lines of code implementation. First, you use the modulus function to find the remainder, which are the passengers on the last bus. Then, to find the empty seats, you use bus capacity minus away the last passengers. https://code.sololearn.com/cAsIKRZH3quK/?ref=app
18th Jan 2021, 4:56 AM
Lam Wei Li
Lam Wei Li - avatar
0
Thank you very much!! :D I was really racking my brain on this for some time. Guess I've still got long ways to go, haha
11th Jan 2021, 12:28 AM
Lyra
Lyra - avatar
0
My code is exactly like yours but I never added % what is it used for?
12th Jan 2021, 7:19 AM
Geoffrey Muli
Geoffrey Muli - avatar
0
Geoffrey Muli The modulus operator (%) is informally known as the remainder operator because it returns the remainder after an integer division. https://www.sololearn.com/learning/1609/
12th Jan 2021, 7:47 AM
Vasile Eftodii
Vasile Eftodii - avatar
0
Thanks guys for the help I really appreciate it
21st Jan 2021, 7:31 AM
Geoffrey Muli
Geoffrey Muli - avatar
- 1
Hey 👋 guys check out my super program it has given me headache for three straight days https://www.sololearn.com/Discuss/2676969/?ref=app
25th Jan 2021, 3:12 PM
Geoffrey Muli
Geoffrey Muli - avatar