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.
15 ответов
+ 3
I don't give ready-made codes. Show your attempt. Re-read the previous lessons, then try the task.
+ 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
+ 1
Input means we are supposed to take user input with cin
+ 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
+ 1
(x % 50 != 0) * (50 - x % 50)
+ 1
Swati Kumari
a = bq + r
0 < r < |b|
Which means
16 = 3 * 5 + 1
b = 3
remainder = 1
0
Please show your attempt and link your code.
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
0
You need to take the number of passengers as input. Why do you divide by 2?
0
x is my input and the 2 us for the number of busses having said that the first and last.
0
Ok, so u take input dsta for number of passengers, thanks. Let mw try it out.
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
0
Hi
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).