- 10
Transportation program in c++ plz tell me
14 Respuestas
+ 3
Hii,
SoloLearn has already given you the explanation about the problem.
"The first bus will transport 50 passengers, leaving 126-50=76 in the station.
The next one will leave 76-50 = 26 in the station,
thus, the last bus will take all of the 26 passengers, having 50-26=24 seats left empty."
They even provide this hint.
"The modulo operator % can help to determine the number of passengers for the last bus."
For further assistance please link your code.
Thanks!!
+ 2
Kindly clarify for what you are asking for!
+ 2
A simple three lines of code implementation.
First, you use the modulus function to find the remainder, which are the passengers on the last bus.
Then, to find the empty seats, you use bus capacity minus away the last passengers.
https://code.sololearn.com/cAsIKRZH3quK/?ref=app
+ 1
You can always do it the long way like I did.
#include <iostream>
using namespace std;
int main() {
const int buscapacity = 50;
int waitingpassengers;
int remainingpassengers;
int seatsleft;
cin >> waitingpassengers;
if (waitingpassengers > 50)
{
do {
remainingpassengers = waitingpassengers - buscapacity;
waitingpassengers = remainingpassengers;
if (remainingpassengers <= 50) {
seatsleft = buscapacity - remainingpassengers;
}
} while (remainingpassengers > 50);
}
else
{
seatsleft = buscapacity - waitingpassengers;
}
cout << seatsleft;
return 0;
}
0
I have written the code but how do get the input our return the output???????
Here is my code:
int Passengers;
cin >> Passengers;
int EmptySeats = 126;
EmptySeats -= Passengers % 50
cout<< EmptySeats<<endl;
- 1
#include <iostream>
using namespace std;
int main(){
// your code goes here
int a, b, c, z;
b = 50;
cin>>c;
// a = ?
a = c % b;
z = b - a;
cout<<z<<endl;
}
- 2
#include <iostream>
using namespace std;
int main() {
//your code goes here
int c,how;
cin>>how;
if(how>50)
{
how=how%50;
}
c=50-how;
cout<<c;
return 0;
}
easy
- 2
#include <iostream>
using namespace std;
int main(){
// your code goes here
int a, b, c, z;
b = 50;
cin>>c;
// a = ?
a = c % b;
z = b - a;
cout<<z<<endl;
}
- 3
Soumik You get input from cin into the variable Passengers. For the example that is 126. Do your calculations with the variable Passengers.
Be aware that 126 is only an example. Don't use fixed values from examples or test cases in your code, they are provided from input (cin).
Repeat that chapter from the course if you need, to understand the concept
- 4
How
- 5
This is not a free programming service. Don't be brazen.
- 6
Plz write a program