How to make a program for a bus service. A bus can transport 50 passengers at once. Given the number of passengers waitin | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
- 2

How to make a program for a bus service. A bus can transport 50 passengers at once. Given the number of passengers waitin

I'm having trouble with this one, I need help

14th Jan 2022, 7:50 PM
Derrick Simpamba
Derrick Simpamba - avatar
6 Antworten
+ 3
Triple999 Read carefully, the bus can hold 50 passengers, not 150. We want to divide up the passengers into groups of 50 and then use the remainder to see how many seats are available on the last bus. To get the remainder after dividing by 50, use the modulo operator like this: ans = a%50; But wait. That calculates the remainder of passengers on the last bus, not how many seats are empty. Be sure to subtract the number of passengers from total seats on the bus to get empty seats and print that result. Also focus on your cout statement and consider correcting which variable it is printing.
14th Jan 2022, 11:28 PM
Brian
Brian - avatar
+ 3
If you need help, share your attempt so we can help you!
14th Jan 2022, 9:15 PM
CGM
CGM - avatar
+ 2
#include <iostream> using namespace std; int main() { //your code goes here int a, ans; cin >> a; ans = 150 % a; cout << a; return 0; }
14th Jan 2022, 9:29 PM
Derrick Simpamba
Derrick Simpamba - avatar
+ 2
Thank so much, let me try it out
15th Jan 2022, 2:41 PM
Derrick Simpamba
Derrick Simpamba - avatar
+ 1
I appreciate your help, I finally did it! #include <iostream> using namespace std; int main() { //your code goes here int a, ans; cin >> a; ans = a % 50; ans = 50 - ans; cout << ans; return 0; }
15th Jan 2022, 2:51 PM
Derrick Simpamba
Derrick Simpamba - avatar
+ 1
Triple999 good work!
15th Jan 2022, 3:05 PM
Brian
Brian - avatar