Hell me out here pals I am unable to write this code C++. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hell me out here pals I am unable to write this code C++.

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. Sample Input: 126 Sample Output: 24 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.

18th Apr 2021, 6:08 PM
Paul Kariuki
Paul Kariuki - avatar
6 Answers
+ 1
Martin Taylor is right. Problem can be solved in single line: int result = (50 - num_of_passengers % 50)% 50;
18th Apr 2021, 10:58 PM
Sharofiddin
Sharofiddin - avatar
+ 1
Martin Taylor thats why I added % 50 at the end of expression.
19th Apr 2021, 8:56 AM
Sharofiddin
Sharofiddin - avatar
0
Use search bar please, there are a lot of questions about this, at least a few every week
18th Apr 2021, 6:16 PM
Michal Doruch
0
Ok
18th Apr 2021, 6:21 PM
Paul Kariuki
Paul Kariuki - avatar
0
Thank you
18th Apr 2021, 7:26 PM
Paul Kariuki
Paul Kariuki - avatar
- 1
Just use while loop for transportation of buses... it's easy try to implement first if you stuck then ask your problem here... don't just ask for others codes.. by seeing others code build your own logic... happy coding! 😉 https://code.sololearn.com/cFtuhlCwucwF/?ref=app
18th Apr 2021, 7:00 PM
Ratnapal Shende
Ratnapal Shende - avatar