0

Please the Transportation Question in c++

Can someone teach me how to solve it

7th Jun 2021, 1:00 PM
Ricky Mills
Ricky Mills - avatar
19 Réponses
+ 1
First you have to get the number of passengers int passengers; cin >> passengers; then you have to find how many passengers are left int remainPass = passengers % 50; then you have to find how many seats are left int remainSeats = 50 - remainPass;
14th Oct 2021, 1:57 PM
Eng-Abdulrahman Alsuhaibi
Eng-Abdulrahman Alsuhaibi - avatar
0
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. Let's decide step by step. Step 1: Create a variable and assign the input data to it, (the number of passengers at the stop)
7th Jun 2021, 3:37 PM
Solo
Solo - avatar
0
The 26 and 14 you use are undefined variables and won’t be the same in every case. The amount of passengers on the last possible bus is dependent on the total start amount. That is (total start) % 50, which the example gives 126 % 50 = 26 ( 50 + 50 + 26). From there you just subtract 50 from you modulus value (26) for your remaining open seats (24) since. Here is my code: #include <iostream> using namespace std; int main() { int passengers; cin>>passengers; /*input given for total passengers */ if(passengers > 50){ cout<< 50 - (passengers%50); /* passengers % 50 gives you the amount of passengers on the last bus. Subtract that from 50 to get the empty spaces on that bus*/ }else{ cout<<50-passengers; /* if below 50 then theres only one bus trip so you can just subtract the passengers from the total amount of seats to get the empty seats.*/ } return 0; }
7th Jun 2021, 9:23 PM
Roderick Davis
Roderick Davis - avatar
0
Vasiliy he seemed to be lacking basic understanding of modulus operation and if-else logic and he’d been stuck awhile so I thought maybe visual learning was the best
7th Jun 2021, 11:20 PM
Roderick Davis
Roderick Davis - avatar
- 1
How long have you been trying to solve this problem and what results have you come to?
7th Jun 2021, 1:19 PM
Solo
Solo - avatar
- 1
For weeks now
7th Jun 2021, 1:25 PM
Ricky Mills
Ricky Mills - avatar
- 1
I wish I can screenshot the QQuestion for you
7th Jun 2021, 1:29 PM
Ricky Mills
Ricky Mills - avatar
- 1
So theres two cases, more than 50 passengers and 50 passengers or less. 50 passengers or less, like the last line of the example: 50 - passengers = seats left empty. Over 50 passengers would be where you can use modulus operater %. So it would be passengers%50 giving you the remaining passengers (not seats) and you can use the math from the first case to solve for the remaining seats.
7th Jun 2021, 1:45 PM
Roderick Davis
Roderick Davis - avatar
- 1
This can be done with an if-else statement, please show your attempt.
7th Jun 2021, 1:46 PM
Roderick Davis
Roderick Davis - avatar
- 1
Thanks Sir I feel I have a little knowledge of C++
7th Jun 2021, 10:20 PM
Ricky Mills
Ricky Mills - avatar
- 1
Roderick Davis , you gave a very good explanation for solving the problem, but why did you write a ready-made solution, why do you deprive Ricky of doing it himself 🙁
7th Jun 2021, 10:49 PM
Solo
Solo - avatar
- 1
If he left me I will be very confused
7th Jun 2021, 11:15 PM
Ricky Mills
Ricky Mills - avatar
- 1
It's ok I understand but i don't know how to use them and when I should use them.
7th Jun 2021, 11:23 PM
Ricky Mills
Ricky Mills - avatar
- 2
Can you link the question?
7th Jun 2021, 1:16 PM
Roderick Davis
Roderick Davis - avatar
- 2
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.
7th Jun 2021, 1:30 PM
Ricky Mills
Ricky Mills - avatar
- 2
Please this the Question
7th Jun 2021, 1:30 PM
Ricky Mills
Ricky Mills - avatar
- 2
Int remainder ; remainder =(50%26)+14; cout << remainder;
7th Jun 2021, 2:15 PM
Ricky Mills
Ricky Mills - avatar
- 2
I'm not getting it clearly
7th Jun 2021, 9:11 PM
Ricky Mills
Ricky Mills - avatar