C++ quiz | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

C++ quiz

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. Can anyone solve this challenge

5th Dec 2020, 10:15 PM
Ikechukwu Mabel Precious
Ikechukwu Mabel Precious - avatar
3 Réponses
+ 8
#include <iostream> using namespace std; int main() { int passengers; cout << ""; cin >> passengers ; int left_passengers= passengers % 50; if(left_passengers == 0) { cout << "0 seats left"; } else{ int left_seats= 50 - left_passengers; cout << left_seats; cout << ""; } return 0; }
5th Dec 2020, 10:38 PM
Ikechukwu Mabel Precious
Ikechukwu Mabel Precious - avatar
0
Ikechukwu Mabel Precious , even easier than you written - remove all additional text from the output and print only the number of left_seats calculated after removing the if-else part.
5th Dec 2020, 10:45 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
C++
3rd Dec 2023, 6:23 AM
CH Muzamil
CH Muzamil - avatar