Hi everyone am facing problems with the code for the below question pls help me anyone | SoloLearn: Learn to code for FREE!

+8

Hi everyone am facing problems with the code for the below question pls help me anyone

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. Using c++

c++

11/24/2020 2:12:50 PM

Priya Sahi

36 Answers

New Answer

+9

#include <iostream> using namespace std; int main() { int passengers; cout << "Please enter passenger's number, Output:- "; cin >> passengers ; int left_passengers= passengers % 50; if(left_passengers == 0){ cout << "0 seats left"; } else{ int left_seats= 50 - left_passengers; cout << left_seats; cout << " seats left"; } }

+2

Write code for just 150%126

+2

Rahul you may not read all the answers.. Question is about "having 3 buses with capacity 50", input passenger 126 then you don't have to consider <150 or less than 50... Is not it?

+2

The solution should just output the number and nothing else lest your code will be tagged wrong even though it is right. This is what I mean by that; #include <iostream> using namespace std; int main() { //your code goes here int pasNo; int remSeat; cin >> pasNo; remSeat = pasNo % 50; remSeat = 50 - remSeat; cout << remSeat; return 0; }

+1

I need the ans for no of seats left in the last bus

+1

This isn't difficult... #include <iostream> using namespace std; int main() { int numberOfPassengers; int modulus; cin >> numberOfPassengers; modulus = numberOfPassengers % 50; if (modulus == 0) { cout << "The last bus left with no empty seats." << endl; } else { cout << "The last bus left with " << 50 - modulus << " empty seats." << endl; } return 0; } The only special case you need to be aware of is if the modulus is 0. This means that all busses will leave full. For example if there are 50, 100, or 150 people waiting. Hence the if statement to test for it. The modulus of the calculation effectively tells you how many people remain after all of the full busses leave.

+1

https://code.sololearn.com/cvM23HS0AQzU/?ref=app

+1

Hi R V , I think to find total bus needed we have to use / division operator instead of % modulus . And. If I give input of 50 passenger's (any multiple of 50 )then adding one extra bus is not needed when tp / 50 == 0 .

+1

Malavika Menon thank u mam I got the answer

+1

Bro you print 50-n%150

0

What have you tried so far? Hint: The modulo, or modulus, operator % gives the remainder of a division. https://en.cppreference.com/w/cpp/language/operator_arithmetic

0

Hi i have tried using modulo but i didn't get the output kindly refer me how to wrote the program

0

You need to maintain a counter which is initially equal to 50 then as per s people arrived counter decrease so you can calculate vacant seats

0

Which operators I will use here tell me sir

0

number of buses?

0

We use 3 buses for this

0

Pls send the complete question with constraints

0

Sir there are 126 passenger in the bus station in first bus 50 will go then 126-50=76, in next bus the next 50 passenger will go so that 76-50=26, at final in last bus will take 26 passenger means there is 24 seats are left I want the code for this using c++

0

Priya Sahi the answer to this is simple assume x as the given total people waiting for bus remainder of x /50 would give the seats filled in last bus 50 - seats filled in last bus = empty seats eg: 99 people standing remainder of 99/50 49 50-49= 1 vacant seat in last bus I leave the solution as a code up to you as this is an excersise

0

I need program using modulus plz anyone help me