+ 3
Hello I'm new to this app. Can someone kindly explain to me how to solve this problem with using modulo operator?
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.
13 ответов
+ 4
It was in the lesson 11 Code Project. Anyway, thanks for answering my questions. I got the right code now.
#include <iostream>
using namespace std;
int main() {
//your code goes here
int z;
cin >> z;
int diff = z%50;
int x = 50-diff;
cout << x;
return 0;
}
+ 3
Clint Jake Alfante I'm glad it worked out! Sorry for my confusing you, I was thinking of a completely different problem!
+ 2
Alexander Thiem Oh, actually you were right! I'm thinking of a completely different problem!
Clint Jake Alfante Ah, I see. Next time, it's even more helpful if you put the lesson number so we can see where you are.
+ 1
The modulo operator returns the remainder of a division.
A=104
B=50
C=A/B (=2)
D=A%B (=4)
A equals B*C+D
Now try to use this in your code… if it still doesnt work: post your attempt here: we cant give you further help without knowing where the problem lies
+ 1
Well what is the remainder of 12 by division through 50? Well it is 12…
What does the number mean? 12 people left for the last bus…
What does the problem eant from you? The number of empty seats left…
+ 1
Sorry Justice but NO
Edit: missleading answer from justice was removed.
The modulo operator already did the work of the loop… (subtracting 50 untill the number is below 50)…
He just needs to calculate empty seats instead of full seats in the last bus…
+ 1
It was fine. It is better to have some to talk to when learning new things.
0
Do you have an attempt?
0
Almost correct i think…
Look at what it outputs and what it shoukd outout for some example inputs
0
I did but the thing is it not the same. The test cases have a different output than my code. Like my test case 1 where the input is 12 and the exact output is 38 but my output is still 12.
0
This problem is from the basics only I still haven't gotten to the lessons about looping.
- 1
This is what I did.
I'm not sure of what is wrong.
#include <iostream>
using namespace std;
int main() {
//your code goes here
int z;
cin >> z;
int diff = z%50;
cout << diff;
return 0;
}
- 1
#include <iostream>
using namespace std;
int main(){
int totally=126;
while(totally>50){
totally-=50;
}
cout <<abs(50-totally);
return 0;
}