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.
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;
}
+ 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;
}
+ 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;
}
+ 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;
}
+ 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.
+ 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;
}
+ 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;
}
+ 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.
+ 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.
+ 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;
+ 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;
}
+ 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;
}
}
0
Martin Taylor
Oh yeah! That's right. I get it.😄
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;
}
0
but the answer wasn't expecting if statements
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;
}
0
#include <iostream>
using namespace std;
int main() {
int passengers, empty;
cin>>passengers;
passengers = passengers % 50;
empty = 50-passengers;
cout<< empty<<endl;
return 0;
}
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;
}
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;
}
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;
}