C++ Transponation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ Transponation

Hi everyone am facing problems with the code for the below question pls help me anyone 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. Using c++ Without if clauses. I tried this so far But it seems to be wrong int main() int seats; int passenger; seats = 50; cin >> passenger; cout << passenger % seats << endl; Return 0;

26th Nov 2020, 1:43 PM
Samiii61
6 Answers
+ 3
i know its not the right way but it worked: #include <iostream> using namespace std; int main() { //your code goes here int x; int y = 50; int sum; cin >> x; x = x % 50; sum = x - y; cout << -sum << endl; return 0; }
26th Nov 2020, 2:06 PM
Samiii61
+ 2
You are quite close, however, you are missing the last step. Until now, you have calculated how many passengers the last bus will transport, via passenger % seats But the task wants you to output the number of empty seats for the last bus, which would be the total number of seats subtracted by the amount of passengers on that bus. Try to incorporate this into your solution.
26th Nov 2020, 1:49 PM
Shadow
Shadow - avatar
0
Shadow can you show me a better way?
26th Nov 2020, 2:07 PM
Samiii61
0
The term -( x - y ) is equivalent to ( y - x ), but other than that, there isn't really a much better way. You can shorten it of course to a single line, i.e. 50 - ( passenger % 50 ) but that is practically the same.
26th Nov 2020, 2:11 PM
Shadow
Shadow - avatar
0
okay thanks mate :)
26th Nov 2020, 2:30 PM
Samiii61
- 1
Anyone tell me how run this program?
9th Dec 2020, 12:06 PM
Amna
Amna - avatar