+ 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 。^‿^。
10 ответов
+ 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;
}
+ 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.
+ 1
it doesnt work try to run it Rik Wittkopp it will give 0 ,or maybe thats just for me ? try
+ 1
learner
The code you have posted works fine.
+ 1
thank you Rik Wittkopp
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
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
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
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.
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