+ 2

how to solve c++ problem without elif and if

here's the question i'm a noob please help 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. seems like it needs and if and some other statements to make it work is there any other way

13th Feb 2021, 4:17 PM
max bertolimo
max bertolimo - avatar
3 Respuestas
+ 8
Yes, it is possible without elif and if, just interpret and analyze the problem then turn it into equation. You can use operations, % and -. Modulus (%) ---> To get the passengers from the last bus Subtraction (-) ---> To get the free seats
13th Feb 2021, 4:21 PM
noteve
noteve - avatar
+ 3
This question can be solved without using if elif. Just by using this one line you can calculate empty seats in the last bus will have. cout<<50-(no%50); where no is int type input.
13th Feb 2021, 4:36 PM
Hrutik Bhalerao
Hrutik Bhalerao - avatar
+ 3
C++ uses "else if" and not "elif".
13th Feb 2021, 9:07 PM
Sonic
Sonic - avatar