- 6

You are making a program for a bus service. A bus can transport 50 passengers at once. Given the number of passengers waitin

Help

28th May 2021, 6:19 PM
Walid
Walid - avatar
7 Answers
+ 8
Djebbar Walid , before we are going to help you, please present your attempt here. if you haven't done a try by yourself so far, please do so. create your code in playground and post the link to it here. please also provide a proper task description with sample of input and output. thanks!
28th May 2021, 6:45 PM
Lothar
Lothar - avatar
+ 2
I'm afraid just saying 'help' without giving any code to go with it won't help much but I'll try. Assuming all buses carry a maximum of 50 passengers at any one time. const int max_passengers = 50; // assume that there are n number of people waiting at a bus stop int waiting = n; //n being how many people are waiting if (waiting <= max_passengers){int free_seats = max_passengers-waiting; Console.WriteLine("There are " + Convert.ToString(free_seats) + " seats left");} else if (waiting > max_passengers){int wait = waiting-max_passengers; Console.WriteLine(Convert.ToString(wait) + "people are waiting for another bus to arrive");} I hope that helps 🙂
28th May 2021, 6:54 PM
Zak Polley
Zak Polley - avatar
+ 2
Zak Polley thanks bro😊
28th May 2021, 8:10 PM
Walid
Walid - avatar
+ 1
#include <iostream> using namespace std; int main() { int x,y,z,i; //x is the number of total passengers a bus can transport x=50; //y is the number of total passengers waiting in the bus station cin >> y; if (y<x); {i=x-y; } if (y>x); {z=y%x; //z is the number of passengers left i=x-z; } //seats left empty cout << i; return 0; }
18th Jun 2021, 7:30 AM
Abhisek Kar
Abhisek Kar - avatar
+ 1
Thanks bro
18th Jun 2021, 7:27 PM
Walid
Walid - avatar
0
If the question is to get how many people will be on the last bus then Console.WriteLine(passengers%50)
29th May 2021, 5:50 AM
Eashan Morajkar
Eashan Morajkar - avatar
0
The problem is this task appears before the introducation of if, while etc.
21st Mar 2022, 8:10 PM
Mj Yoo