Section 1 Transportation Project | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Section 1 Transportation Project

Part 1/2 So I’ve tried to solve this project almost a dozen times, but I just don’t understand the problem! This the current (and closest iteration): #include <iostream> #include <string> using namespace std; int main() { //your code goes here // number of passengers (176); using max capacity of 50, empty seats remaining int pass; int max = 50; cout << "How many passengers are there?\n"; cin >> pass; int empty = pass % max; cout << "There will be " << empty << " spare seats."; return 0; }

28th Nov 2020, 5:42 PM
Sir Starshine
Sir Starshine - avatar
3 Answers
Right now, you are calculating the number of passengers on the last bus, not the amount of empty seats. To obtain the amount of empty seats, you need to subtract the number of passengers from the number of total seats availaible. Furthermore, when solving for automated test cases evaluated by a machine, you need to make sure that your output matches the required output format given in the description. If you print anything else, the evaluation will be false even if your result might be correct. The <string> header is already included by <iostream> and additionally has nothing to do with std::endl, so including it wouldn't solve any problem you might have with it. Sounds like you tried to use std::endl with std::cin, which would naturally lead to an error as std::endl is used to insert a newline and flush the output stream, not the input stream.
28th Nov 2020, 6:57 PM
Shadow - avatar
+ 3
A simple three lines of code implementation. First, you use the modulus function to find the remainder, which are the passengers on the last bus. Then, to find the empty seats, you use bus capacity minus away the last passengers.
16th Dec 2020, 12:39 PM
Lam Wei Li
Lam Wei Li - avatar
Part 2/2 Using this code, the IDE takes the input and somehow uses that as the result. Before this though, I used endl for cin and cout, which resulted in an error concerning istream and ostream. This prompted me to include <string> as well, just as a precaution.
28th Nov 2020, 5:47 PM
Sir Starshine
Sir Starshine - avatar