- 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
7 ответов
+ 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!
+ 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 🙂
+ 2
Zak Polley thanks bro😊
+ 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;
}
+ 1
Thanks bro
0
If the question is to get how many people will be on the last bus then
Console.WriteLine(passengers%50)
0
The problem is this task appears before the introducation of if, while etc.