0

Help me solve this plz.

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 left empty.

1st Dec 2020, 3:45 PM
Leo BAHER
Leo BAHER - avatar
55 Answers
+ 55
#include <iostream> using namespace std; int main() { int passengers; cout << ""; 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 << ""; } return 0; }
21st Mar 2021, 4:07 AM
Maruf Ashurov
Maruf Ashurov - avatar
+ 32
#include <iostream> using namespace std; int main() { int pass, empty_seats; cin>>pass; pass=pass%50; empty_seats=50-pass; cout<<empty_seats; return 0; }
20th Apr 2021, 6:38 PM
Nicolau Bianca
Nicolau Bianca - avatar
+ 11
#include <iostream> using namespace std; int main() { //your code goes here int passengers; cin>>passengers; int bus=50; int c; c=passengers%bus; if(c==0){ cout<<"0"; }else{ cout<<bus-c; } return 0; }
27th Aug 2021, 6:09 AM
Vinayak vs
+ 8
#include <iostream> using namespace std; int main(){ int pass; int leave; int waiting; pass = 50; cin >> waiting; leave = waiting%pass; cout << pass-leave; return 0; }
23rd Aug 2021, 5:36 AM
Eren Der Teufel
Eren Der Teufel - avatar
+ 5
Hi! Here is the code I made to solve this problem: #include <iostream> using namespace std; int main() { //your code goes here int a,c,d; c=50; cin>>a; if (a>c) { d=a%c; cout<<50-d; } if (a<c) { d=c-a; cout<<d; } return 0; } 100%works. Hope it helped.
4th Jun 2021, 6:19 AM
Diyaan Bhat
Diyaan Bhat - avatar
+ 3
//This code will definitely work🤟🤟 #include <iostream> using namespace std; int main() { int passengers; //cout << "Please! Enter the passenger " << endl; cin >> passengers ; int leftPassengers = passengers % 50; if(leftPassengers == 0){ cout << "No seat vacant"<<endl; } else{ leftPassengers = abs(leftPassengers - 50); // abs() is used for +ve intiger value cout<<leftPassengers<<endl; } return 0; }
10th May 2021, 5:52 AM
Nishant Chauhan
Nishant Chauhan - avatar
+ 2
#include <iostream> using namespace std; int main() { //your code goes here int passengers, seats; cin >> passengers; /*Takes user input (Amount of passengers) */ passengers = passengers % 50; /* This will help us get the remainder for the last bus */ seats = 50 - passengers; /* Since the remainder has to be smaller than 50 as the code above helps us find the remainder after entering 50 as many times as possible into passengers. We must do 50 - passengers, not the other way around or we will get a negative */ cout << seats << endl; /* Prints the avaliable seats */ return 0; }
19th Sep 2021, 8:15 PM
Malik Mehrab Rashid
Malik Mehrab Rashid - avatar
+ 1
You can simply use 126%50.. it will the remainder, that is, the number of seats occupied at last bus.. so you can subtract it from 50, to get the empty seats.. Summning up, answer = 50 - (input%50) [edit] as Martin Taylor said, if the number of passengers is a multiple of 50, then seats empty will be 0, so first check for this case, and than go for the above answer.
1st Dec 2020, 3:52 PM
Charitra
Charitra - avatar
+ 1
#include <iostream> using namespace std; int main() { //your code goes here int a , b; cin >> a; a = a % 50; b = 50 - a; cout<< b << endl; return 0; } Hope it helps, Happy Coding.
15th Jun 2021, 5:50 AM
louise angelo nathanoel galang
+ 1
The solution wasnt calling for if statements as they havent been covered yet. This made it seem way more difficult than it should have been. int passengers, empty_seats; int capacity = 50; cin >> passengers; // take the input and reassign the variable passengers = passengers % capacity; // empty seats are the capacity of the bus minus the amount of passengers empty_seats = capacity - passengers; cout << empty_seats;
31st Aug 2021, 12:41 AM
Travis Crawford
Travis Crawford - avatar
+ 1
#include <iostream> using namespace std; int main() { // let x be your choice of input. int x; cout<<"enter a value x"<<endl; cin>>x; while(x>50){ //this will remove 50 for as long as x is bigger than 50. x -=50; } //This will find the empty seat when the loop is satisfied (i.e when x becomes lesser than 50. cout<<50-x; }
24th Jun 2022, 10:26 AM
STANLEY EJIMADU
+ 1
#include<iostream> using namespace std; int main() { int p, s, bus = 50; int left_p; cin>>p; left_p = p%bus; if( left_p < bus) { s = bus - left_p; cout<<s<<endl; } else if(left_p > bus) { s = bus - (left_p - bus); cout<<s<<endl; } else { s = 0; cout<<s<<endl; } }
28th Sep 2022, 1:20 PM
Darshit Vaghasiya
Darshit Vaghasiya - avatar
0
Martin Taylor Oh yeah! That's right. I get it.😄
1st Dec 2020, 4:25 PM
Charitra
Charitra - avatar
0
#include <iostream> using namespace std; int main() { int passengers; cout << ""; 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 << ""; } return 0; }
5th Dec 2020, 10:31 PM
Ikechukwu Mabel Precious
Ikechukwu Mabel Precious - avatar
0
but the answer wasn't expecting if statements
27th Mar 2021, 2:45 PM
Jerald Lashy Jeffery
Jerald Lashy Jeffery - avatar
0
#include <iostream> using namespace std; int main() { //your code goes here int pass = 0, empty = 0; cin >> pass; while(pass > 50){ pass -= 50; } if (pass <= 50){ empty = 50 - pass; } cout << empty; return 0; }
13th Apr 2021, 7:29 AM
Matthew Tangpus
Matthew Tangpus - avatar
0
#include <iostream> using namespace std; int main() { int passengers, empty; cin>>passengers; passengers = passengers % 50; empty = 50-passengers; cout<< empty<<endl; return 0; }
21st Apr 2021, 10:07 PM
Allora
0
#include <iostream> #include <cstdlib> using namespace std; int main() { //your code goes here int seats; cin>>seats; while(seats >= 50){ seats = seats % 50; } cout<<abs(seats-50); return 0; }
30th Jul 2021, 8:49 AM
Charanpreet Singh
Charanpreet Singh - avatar
0
#include <iostream> using namespace std; int main() { int x, y, z, v; cin >> x; y = x / 50; z = x - (50*y); v = 50 - z; cout << v << endl; return 0; }
25th Aug 2021, 10:04 PM
A. D A
0
For easy comprehension, try to read the comments and compare solutions. Don't just copy and paste without a clear understanding of the codes. #include <iostream> using namespace std; int main() { //your code goes here int ans, x, a=0, b=0, c=0; //declaring the variables x=50; //number of passengers per trip cin >> ans; //user's input of several passengers waiting in the bus station a=ans%x; while (x==50){ if (ans<=x || ans==x){ c=x-ans; cout<<c; } else{ b=x-a; cout<<b; } return 0; } return 0; }
15th Sep 2021, 8:50 AM
Adinnuh, Kenechukwu
Adinnuh, Kenechukwu - avatar