+ 1

Transportation Challenge c++

Hi! I just wanted to know if there was a quicker way to solve the following question: You are making a program for a bus service. A bus can transport 50 passengers at once. Given the number of passengers waiting in the bus station as input, you need to calculate and output how many empty seats the last bus will have. I might be missing math fundamentals! Here is my code below: https://code.sololearn.com/c4paY52x970T/?ref=app I appreciate any help! Thank you!

6th Mar 2022, 5:08 AM
Vuko
Vuko - avatar
11 Respuestas
+ 4
int passengers; cin >> passengers ; if(passengers<50 && passengers!=0) { cout<<50 - passengers; } else if(passengers%50!=0) { cout<<50-passengers%50; } return 0;
6th Mar 2022, 5:17 PM
Jackie
Jackie - avatar
+ 1
Thank you for your answer! 😊
6th Mar 2022, 10:50 AM
Vuko
Vuko - avatar
+ 1
Hey Manav, I understand what you are saying, I believe the question could have been phrased better. Explanation: The first bus will transport 50 passengers, leaving 126-50=76 in the station. The next one will leave 26 in the station, thus, the last bus will take all of the 26 passengers, having 50-26=24 seats left empty. 0/50 remaining is an edge case, and yes you could argue it both ways, but fundamentally is immaterial, as long as your code can output on whichever condition you believe in this case, your answer is fine 🙂
8th Mar 2022, 5:12 AM
Vuko
Vuko - avatar
0
cout<< 50- PeopleLine%50;
6th Mar 2022, 5:21 AM
Simba
Simba - avatar
0
Oh thank you for the different view! I appreciate it!
7th Mar 2022, 10:48 AM
Vuko
Vuko - avatar
0
Actually after going over my code I fixed it! cin >> PeopleLine; if(PeopleLine > BusCap) { SeatsRem = BusCap - (PeopleLine % BusCap); } else if(PeopleLine <= BusCap) { SeatsRem = BusCap - PeopleLine; } cout << SeatsRem; return 0; } If the you have 50 passengers, you should not be outputting 50 remaining seats, it should be zero!
7th Mar 2022, 10:12 PM
Vuko
Vuko - avatar
0
#include<iostream> using namespace std; int main() { int b=50; int a; cin>>a; cout<<b-(a%b); return 0; }
30th Jul 2022, 2:57 AM
Saketh Devulapalli
Saketh Devulapalli - avatar