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.
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;
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
0
So cin>> input; is same as
Cin>> 126?
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.
0
Ohh I get it now thanks
0
Tanx
0
short and good!
#include <iostream>
using namespace std;
int main() {
int input;
cin >> input;
cout << 50 - input % 50;
return 0;}