+ 1
C++ quiz
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. Can anyone solve this challenge
3 odpowiedzi
+ 8
#include <iostream>
using namespace std;
int main() { int passengers;
cout << ""; cin >> passengers ;
int left_passengers= passengers % 50;
if(left_passengers == 0)
{
cout << "0 seats left"; }
else{ int left_seats= 50 - left_passengers;
cout << left_seats;
cout << ""; }
return 0; }
0
Ikechukwu Mabel Precious , even easier than you written - remove all additional text from the output and print only the number of left_seats calculated after removing the if-else part.
0
C++