Plz help me to solve one code | Sololearn: Learn to code for FREE!

-2

Plz help me to solve one code

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

12/10/2020 5:52:41 AM

Sanjay

24 Answers

New Answer

+18

See something like this as said earlier use modulo main() { int stationpassengers=0,bus=50,emptyseats=0; cin>>stationpassengers; stationpassengers=stationpassengers % bus; emptyseats=bus - stationpassengers ; cout<<"Empty Seats: "<<emptyseats; }

+11

Some hints: Input the passengers Do some operation to get the passengers in the station(use some operators) Calculate empty seats in the bus by sub. Print the empty seats

+9

Yes show us your code first

+9

#include <iostream> using namespace std; int main() { int passengers, seats; cin>>passengers; while (passengers > 50) { passengers %= 50; } seats = 50 - passengers; cout<< seats; return 0; }

+5

using namespace std; int main() { //your code goes here int x=1; int a; cin>>a; int p; int lim=0; for(int i=1;i>0;++i) { if(lim<a) { lim=lim+50;; } else break; } int y=lim-a; cout<<y<<endl; return 0; } I have added my code to just give you a reference 🤫Don't copy Here I've used a loop for the number of times bus moves In each value of i i need to check whether the entered number is greater than 0 and then add 50 as in the question it is given... Else As soon as the condition is false The loop should break as it would be infinite then.. Hope you understood

+3

IN PYTHON try: passengersNum=input() passengersNum=int(passengersNum ) passeengersLeft= passengersNum % 50 print(50 - passeengersLeft ) except ValueError: print("Input is not a number") OR SIMPLY DO print(50-(int(input())%50)

+3

Guys, it is appreciated that you all are contributing. But sharing the answers directly are against the rules. Some of you have provided answers with explanation, which is ok. But the ones without explanation, please remove your answers, as they are against the rules.

+1

You should first attempt your code to show us that you understand the basic concepts. We will not complete your assignments for you.

+1

Use the modulo operator, which returns the remainder of a division. Your code is half correct.

+1

How to finish this case (solve) #include <iostream> using namespace std; class Queue { int size; int* queue; public: Queue() { size = 0; queue = new int[100]; } void add(int data) { queue[size] = data; size++; } void remove() { if (size == 0) { cout << "Queue is empty"<<endl; return; } else { for (int i = 0; i < size - 1; i++) { queue[i] = queue[i + 1]; } size--; } } void print() { if (size == 0) { cout << "Queue is empty"<<endl; return; } for (int i = 0; i < size; i++) { cout<<queue[i]<<" <- "; } cout << endl; } //your code goes here }; int main() { Queue q1; q1.add(42); q1.add(2); q1.add(8); q1.add(1); Queue q2; q2.add(3); q2.add(66); q2.add(128); q2.add(5); Queue q3 = q1+q2; q3.print(); return 0; }

+1

Please vote it if you like it.

+1

For python print (50-(int(input())%50)) {. } Floor division of the input -> no of seats filled in last bus Getting it's complement (subtracting the result of floor div.) That's it int() function is used to convert the default str input to integer

0

Hint: use the modulo (%) operator. If u yet haven't made your code, are you expecting us to give you the ready made, error proof answer? That would charge you money. 500 INR.

0

#include <iostream> using namespace std; int main() { int a; cout<<enter the number a; cin>>a; y =a-50 cout<<passengers remained in first stop=y; z=y-50 cout<< passengers remained in last stop is z; return 0; }

0

This is my code...but. It is showing error ☝️☝️

0

#include <iostream> using namespace std; int main() { //your code goes here int input = 12;//the number of passengers who waiting on the bus station int input1 = 50;//the heighest available number of seats on the bus int input2;//the number of free seats on the next bus /*cout << "Please write the number of passangers who are waiting on the bus station!" << '\n';*/ cin >> input; input2 = input1 - input % input1; cout /* << "Number of free seats on the current bus is: "*/ << input2; return 0; }

0

#include <iostream> using namespace std; int main() { //your code goes here int input = 12;//the number of passengers who waiting on the bus station int input1 = 50;//the heighest available number of seats on the bus int input2;//the number of free seats on the next bus /*cout << "Please write d number of passangers who are waiting on the bus station!" << '\n';*/ cin >> input; input2 = input1 - (input % 'input1' ); cout /* << "Number of free seats on the current bus is: "*/ << input2; return 0; }

0

See something like this as said earlier use modulo main() { int stationpassengers=0,bus=50,emptyseats=0; cin>>stationpassengers; stationpassengers=stationpassengers % bus; emptyseats=bus - stationpassengers ; cout<<"Empty Seats: "<<emptyseats; }

0

Mention the pro.. Language

0

Mention the pro.. Language Ok