Skip to main content

Sololearn C++ 'Transportation' problem solution and explanation.

Posted on:  at 
Problem Solving
Picture

Problem Explanation:

The first bus will transport 50 passengers, leaving 126 - 50 = 76 in the station.

The next one will leave 76 - 50 = 26 in the station. Thus, the last bus will take all of the 26 passengers, having 50 - 26 = 24 seats left empty.

Problem Hint:

The modulo operator (%) can help to determine the number of passengers for the last bus.

Problem Solution

#include <iostream>
using namespace std;

int main()
{
    int passenger, seats, filledseats, emptyseats;
    seats = 50;
    cout << "Enter passengers amount" << endl;
    cin >> passenger;
    filledseats = passenger % seats;
    emptyseats = seats - filledseats;
    cout << "Last bus filled seats" << endl << filledseats << endl;
    cout << "Last bus empty seats" << endl << emptyseats << endl;
    return 0;
}