0

Transportation 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.

30th Oct 2021, 10:49 AM
Emmanuel Osemudiamen
Emmanuel Osemudiamen - avatar
7 Antworten
+ 1
int input; You have declared a variable named input of type integer. cin>> input; Taking the input from user and storing it in the variable input. cout << 50-input%50; Printing the output to console. input%50 gives the remainder after dividing input by 50 which gives you the number of passenger in the last trip (if not completely divisible by 50). You got the number of passenger in the last trip, just subtract this from 50 to get the sit left empty which is the output;
30th Oct 2021, 11:07 AM
Kashyap Kumar
Kashyap Kumar - avatar
0
#include <iostream> using namespace std; int main() { //your code goes here int input; cin >> input; cout << 50 - input % 50; return 0; } I want an explanation for this code thanks
30th Oct 2021, 10:51 AM
Emmanuel Osemudiamen
Emmanuel Osemudiamen - avatar
0
So cin>> input; is same as Cin>> 126?
30th Oct 2021, 11:14 AM
Emmanuel Osemudiamen
Emmanuel Osemudiamen - avatar
0
Emmanuel Osemudiamen no, you should have a variable for storing what user have entered. cin>>126, in this case where will the number be stored? Hope you understood.
30th Oct 2021, 11:19 AM
Kashyap Kumar
Kashyap Kumar - avatar
0
Ohh I get it now thanks
30th Oct 2021, 11:32 AM
Emmanuel Osemudiamen
Emmanuel Osemudiamen - avatar
0
Tanx
31st Jul 2022, 9:19 PM
Zekaryas Hailu
0
short and good! #include <iostream> using namespace std; int main() { int input; cin >> input; cout << 50 - input % 50; return 0;}
6th Oct 2022, 11:04 AM
Marcel Krättli