I need help with the transportation project (C++) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I need help with the transportation project (C++)

Don't want to take much of your time so I'll try to get to the point. I made a program, that basically does what is asked but with one little condition, the user has to introduce the amount of busses in order to multiply the amount of chairs (being a constant of 50 per bus). Then substracting the amount of passangers from the amount of chair to get the remaining chairs. This technically a right answer, but that is not what SoloLearns wants. int main() { int chairs = 50, bus, passangers, remaining_chairs; cout << "Amount of busses: " << endl; cin >> bus; chairs = chairs * bus; cout << "Amount of passangers: " << endl; cin >> passangers; remaining_chairs = chairs - passangers; cout << "The amount of remaining chairs is: " << endl << remaining_chairs; return 0; } It seems to ask me for a way to get the necesary amount of buses basses on only the amount of passangers as input. But I can only think in two ways to do that. 1. Condition statements. I have basically no prior coding experience so this is only an assumption. Condition statements would allow me to do what is asked, but there are two issues: first, I still dont know about them, and second and most importantly, I still havent seen that class, so it makes no sense that the answer to the project is something I havent studied yet, and I'd like to solve it the way SoloLearn wants me to do it. 2. Modulo operator. Everything, Including the hint of the project itself, aim to the modulo operator being the part of the solution. The issue being, I just don't know how to apply it, I dont mean in a coding sense, but in a logical sense, I'm still not able to see how it could get me to the answer. I would really love some help with the project, and I know such a small program is not good reference, but if there is any observation about the program I wrote in itself, I'd love to read it. I'm just getting into programming, so any advice about common beginner mistakes is welcome, THANK YOU BEFOREHAND. ^_^

13th Oct 2021, 3:49 AM
Kevin Zambrano
Kevin Zambrano - avatar
3 Answers
+ 2
Well consider there are 126 passengers. The first bus will take 50 the second one 50 and the third one 26. So total 3 bus, 50*3-126 = 24. Your logic is correct but the input is only giving the passenger and not the number of bus so how to calculate it is your doubt right? Well 126%50 gives 26 which is the amount of passengers in third bus. Now 50-26 gives the number of remaining seats.
13th Oct 2021, 6:39 AM
Arun Ruban SJ
Arun Ruban SJ - avatar
+ 2
Your program has nice prompts and clearly-labeled output. However, Code Coach expects only one thing printed to the console: the final number. Any extra output will be graded as wrong. Modulo can help because it is like a shortcut for subtracting repeatedly until you cannot subtract any more (which is division). Then its final result is the amount that is left over (the remainder). So passengers % 50 would subtract however many busloads of 50 until the last bus, and return the number of passengers that does not fill out a whole group of 50. The final catch is that the problem asks for how many empty seats, not passengers. So you must subtract remaining passengers from 50 available seats in the last bus. Try 50 - (passengers % 50). That is the answer to print, without prompts or labeling.
13th Oct 2021, 7:55 AM
Brian
Brian - avatar
+ 1
If you want to calculate the number of buses then you just have to take the ceiling from the number of passengers over the amount of seats in one bus, but I don't think it's really necessary to calculate that
13th Oct 2021, 7:01 AM
Michał Mróz
Michał Mróz - avatar