- 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
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.
+ 3
If you need help, share your attempt so we can help you!
+ 2
#include <iostream>
using namespace std;
int main() {
//your code goes here
int a, ans;
cin >> a;
ans = 150 % a;
cout << a;
return 0;
}
+ 2
Thank so much, let me try it out
+ 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;
}
+ 1
Triple999 good work!