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; }
8 Réponses
+ 2
#include <iostream>
using namespace std;
int main() {
int passengersNumber;
cin >> passengersNumber;
cout << 50 - passengersNumber % 50;
return 0;
}
+ 1
Using the "return" clause will exit the current function, thus terminating your program!
+ 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
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
0
My code is exactly like yours but I never added % what is it used for?
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/
0
Thanks guys for the help I really appreciate it
- 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