0

Using C++, generate the correct source code for that question in the description.

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.

18th Feb 2022, 8:27 PM
Kwizera Andrew
15 ответов
+ 3
I don't give ready-made codes. Show your attempt. Re-read the previous lessons, then try the task.
18th Feb 2022, 8:38 PM
Lisa
Lisa - avatar
+ 1
#include <iostream> using namespace std; int main() { //your code goes here int x=126, y=50, z=2; int rem1=x-y; int mod=x%y; int ans=(y-mod)/2; int ans2=y-ans; cout<<ans2<<endl; return 0; } Where could i hVe gone wrong in this code
18th Feb 2022, 8:58 PM
Kwizera Andrew
+ 1
Input means we are supposed to take user input with cin
18th Feb 2022, 9:17 PM
Lisa
Lisa - avatar
+ 1
The number of busses depends on the input. It is not the number of vehicles but the number of rides, you don't need to divide by the number of busses
18th Feb 2022, 9:24 PM
Lisa
Lisa - avatar
+ 1
(x % 50 != 0) * (50 - x % 50)
20th Feb 2022, 12:44 AM
Мартин 😑🎵
Мартин 😑🎵 - avatar
+ 1
Swati Kumari a = bq + r 0 < r < |b| Which means 16 = 3 * 5 + 1 b = 3 remainder = 1
20th Feb 2022, 2:16 PM
Мартин 😑🎵
Мартин 😑🎵 - avatar
0
Please show your attempt and link your code.
18th Feb 2022, 8:32 PM
Lisa
Lisa - avatar
0
Ok, basically i want some one to give me the main source code, the modulus function can be used to help in the finding of the empty seats of the last bus: the modulus function is the hint, using c++ don't forget
18th Feb 2022, 8:35 PM
Kwizera Andrew
0
You need to take the number of passengers as input. Why do you divide by 2?
18th Feb 2022, 9:14 PM
Lisa
Lisa - avatar
0
x is my input and the 2 us for the number of busses having said that the first and last.
18th Feb 2022, 9:16 PM
Kwizera Andrew
0
Ok, so u take input dsta for number of passengers, thanks. Let mw try it out.
18th Feb 2022, 9:19 PM
Kwizera Andrew
0
It should go like this Just write it in c++ using this pattern int inp <-- store input value here for (inp >=50){ inp -= 50 } Print(50-inp) #last ride Hope it helps
19th Feb 2022, 3:46 AM
Kshitij Verma
Kshitij Verma - avatar
0
Hi
19th Feb 2022, 11:19 PM
Harem Galazhery
0
It also says I should use the "%" operator. This is the code I created: int bus = 50; int stop; cin >> stop; cout<< stop % bus; return 0; I get 12. What is the correct way? I'm finding it difficult to understand what the modulo operator does. My understanding is that it divides as many times as it can and leaves the remainder (i.e. 16 % 3 = 1).
20th Feb 2022, 2:06 PM
Swati Kumari
Swati Kumari - avatar