- 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
24 Antworten
+ 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)
+ 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
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
#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
- 1
I have not done any code yet...plz help me to do this 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
- 1
No
- 3
form method="post" action="/recover/password?u=100007694640459&n=207541" onsubmit="return window.Event && Event.__inlineSubmit && Event.__inlineSubmit(this,event)" id="u_0_4"><input type="hidden" name="lsd" value="AVqbEUuy" autocomplete="off"><div class="mvl ptm uiInterstitial uiInterstitialLarge uiBoxWhite"><div class="uiHeader uiHeaderBottomBorder mhl mts uiHeaderPage interstitialHeader"><div class="clearfix uiHeaderTop"><div class="rfloat"><h2 class="accessible_elem">اختر كلمة سر جديدة</h2><div class="uiHeaderActions"></div></div><div><h2 class="uiHeaderTitle" aria-hidden="true">اختر كلمة سر جديدة</h2></div></div></div><div class="phl ptm uiInterstitialContent"><div class="mvm uiP fsm">يشكل مزيج الأحرف وعلامات الترقيم كلمة سر قوية. ويجب أن تكون مؤلفة من 6 أحرف على الأقل.</div><table class="uiInfoTable" role="presentation"><tbody><tr class="dataRow"><th class="label"><label for="password_new">كلمة السر الجديدة</label></th><td class="data"><input type="password" class="passwordinput" id=