+ 1

how can i make a function ,if a is less than 50 use (),if a is more than 50 use() , a is the input

its a question during lesson where it asks me to make a formula for this . input () the bus seats =50 it wants to know the remainder seats for the last bus. so lets say input is 126 bus takes 50 =76 bus takes 50=26 bus takes the remaining =24 empty seats i can use (input %50 )to get this but for less than 50 it doesnt work can use (50-input ) let me know your opinions thank you 。^‿^。

11th May 2022, 6:25 AM
learner
learner - avatar
10 Réponses
+ 5
Rik Wittkopp i got it thank you anyway here is the code format i used #include <iostream> using namespace std; int main() { //your code goes here int a; cin>>a; int b=50; if (a<=50){cout<<b-a;} else {cout<<b-(a%b);} return 0; }
11th May 2022, 7:09 PM
learner
learner - avatar
+ 2
learner Well done, though I still don't understand your initial difficulty 26%50 = 26 So a small number should not have caused you difficulty. However, I am pleased that you perservered and found a solution.
11th May 2022, 8:11 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
it doesnt work try to run it Rik Wittkopp it will give 0 ,or maybe thats just for me ? try
11th May 2022, 8:13 PM
learner
learner - avatar
+ 1
learner The code you have posted works fine.
11th May 2022, 8:42 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
thank you Rik Wittkopp
11th May 2022, 8:44 PM
learner
learner - avatar
0
The % will give you the remaining people for the last bus. 50 - the remaining people will give you the spare seats Your example of 126 people = 26 remaining people = 24 spare seats on last bus
11th May 2022, 6:30 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Rik Wittkopp have you finished lesson 11 in c++ ,it wants me to code ,it will give input and i need to find remaining seats . its easy if the input is larger than 50 but when the input is less i cant
11th May 2022, 6:41 AM
learner
learner - avatar
0
learner Yes, I have completed it using the steps in my previous post. Can you attach your attempt here so we may look at your problem directly
11th May 2022, 7:40 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Rik Wittkopp lost the attempt as i didnt save but here is the question 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.
11th May 2022, 8:38 AM
learner
learner - avatar
0
learner I am aware of the question & I have told you how to solve it, but can't help yoi further if you don't show your code
11th May 2022, 8:57 AM
Rik Wittkopp
Rik Wittkopp - avatar