0
Help me in completing this project
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.
10 Réponses
+ 3
I got u😊😊..so here's my final code and it works😇.....
#include <iostream>
using namespace std;
int main() {
int n,l,r;
/* n=total passengers at station */
cin>>n;
cout<<n<<endl;
l=n%50;
/* r=empty seats in last bus*/
r=50-l;
cout<<r;
return 0;
}
+ 2
#include <iostream>
using namespace std;
int main() {
int n,l,r;
cin>>n;
cout<<"total passengers at station: "<<n;
l=n%50;
r=50-l;
cout <<"\nempty seats in last bus: "<<r;
return 0;
}
I did this..is it right?
+ 1
Post your attempt please, that wouldn't be "helping you complete" the project. We would just be doing the project for you
+ 1
I dont know cpp but yeah, the formula looks just fine.
You got the total amount, got the remainder when modded with 50, and subtracted the remainder from the total number of seats. You should have your answer.
print em out and see if your answer makes sense
Prakash Kumar Suthar EDIT: Just checked your code out and it works fine. Just cut out that extra text, Sololearn usually only looks for the minimum in it's output
0
About which extra text u are saying to cut?
0
Check the sample that input is 126 and output is 24 only.. Remaining all text in output is not needed...
0
total passengers...
and
empty seats...
in challenges, it shouldn't have anything else than the correct output printed. No prompts for user, no extra text to make the output make more sense, none of that. Just print the answer
0
Awesome man, keep it up!
0
Prakash Kumar Suthar ur final answer looks good.. but if i were u i wouldnt use that many variables.. especially in c++ with all this memory management..
instead do :
int p;
cin >> p;
p %= 50;
cout << 50 - p;
0
int a;
cin >> a;
cout << 50 - a % 50;
// An easier approach