+ 3
How do i Solve this C++ Code coach problem?
I am not able to solve the first project of the C++ course 'Transportation'. Can Anyone please help me solve this problem? This is the link: https://www.sololearn.com/learning/eom-project/1051/902
7 Réponses
+ 7
Hints:
--> You can first use the modulus operator (%) to know how many people are there in the LAST BUS
Example of % operator:
102 % 50 == 2
// we got 2 which is the remainder of the result
--> You can use subraction (-) to calculate the number of FREE SEATS in the LAST BUS
- - - - - - - - - - - - - - - - - - -
Note that in the problem the expected output is the NUMBER OF FREE SEATS IN THE LAST BUS.
- - - - - - - - - - - - - - - - - - -
If you encounter some errors or bugs that you cant solve or figure out, just show us your attempt and so we may help you fix it. Thanks and good luck! 🙂
+ 3
Can you please tell me that the number of buses is 3 or the value changes depending on the number of passengers?
+ 2
Aditya You can get the number of passengers in the last bus regardless of the number of buses by the equation
passengers % capacity
passengers is the input and capacity is the maximum capacity of a single bus which in the problem is 50.
The result will become the remaining no. of passengers in the last bus.
+ 1
Ok!
+ 1
I have completed this in my videoes. :
https://youtu.be/yCap753OQo4?si=Ijb4vcBEA_NZ0xv4
0
#include <iostream>
using namespace std;
int main() {
//your code goes here
int passenger = 126;
int bus =50;
int first = passenger % bus;
int second = bus - first;
cout <<second<<endl;
return 0;
}
0
Hello guys, I don"t understand what is wrong with my code.
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
int main()
{
int bus = 50;
int people_waiting ;
int empty_seats;
int takenseats;
int people_left;
int people_left_2;
cout << "";
cin >> people_waiting;
people_left = people_waiting - bus;
takenseats = bus% people_left;
empty_seats = bus - takenseats;
cin >> people_waiting;
people_left_2 = people_waiting - bus;
takenseats = bus% people_left_2;
empty_seats = bus - takenseats;
cout << "" << empty_seats << "" << endl;
return 0;
}