+ 1
Could someone help me solve this? Im not sure what im doing wrong, please tell me what im doing wrong and explain a solution
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. //my code #include <iostream> using namespace std; int main(){ int bus_1, bus_2 = 50; int passengers; int last_bus; int station_1, station_2; cin >> passengers; station_1 = passengers - bus_1; station_2 = station_1 - bus_2; last_bus = station_1 % 50; return 0; }
5 odpowiedzi
+ 3
Useless Players
Your mistakes,
1) you didn't initialised bus_1 with a value.
2)You are assuming the passengers to be a fixed number like 126 .
3) last_bus=station_1%50 will return 26(number of passengers) if the passenger count is 126 and bus_1 is initialised with value 50.
Instead ,for the last bus you should have done (50-station_1) which will return the number of empty seats in last bus.
+ 3
First of all you missed to use cout method to print the output.
Also, you need to calculate the remaining seats not passengers
last_bus = bus_2 - passengers % 50;
cout << last_bus;
+ 2
@lpang i know that but i would also like feedback on my code specifically, and why it may not be efficient or if it is completely in the wrong direction of the solution. Thank you though.
+ 1
Please try to search before posting. Many people had tried to complete that task and ask questions around. Here's a search result from Most Popular section using 'transportation' search term.
https://www.sololearn.com/Discuss/2607271/?ref=app
+ 1
Useless Players
The challenge is not interested in the previous buses, as indicated in your code, only in how many empty seats are on the last bus.
So
Step1. Create an integer input.
lets call it 326 // passengers
Step2. buses come and go with 50 passengers, how many are left?
Use % to ascertain remainder
//26 passengers.
Step3. How many empty seats?
Bus capacity - remainder
50 - 26 = 24