I need help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I need help

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. This is my code 👇 #include <iostream> using namespace std; int main() { //your code goes here int num; cout <<"enter the number of passengers:\t"<<endl; cin>>num; int busSeats=50; int next_station=num%busSeats; int seats_free=busSeats-next_station; if(num>=50){ cout <<"seats is"<<seats_free; } else{ cout<<"seats is \t"<<50-num; } }

15th Jul 2021, 9:19 AM
MOHAMED THOUFIC YOUSUF
7 Answers
+ 3
It's not necessary to add extra information in your solution I mean your output should be matched with expected output #include <iostream> using namespace std; int main() { //your code goes here int num; //cout <<"enter the number of passengers:\t"<<endl; cin>>num; int busSeats=50; int next_station=num%busSeats; int seats_free=busSeats-next_station; if(num>=50){ cout <<seats_free; } else{ cout<<50-num; } }
15th Jul 2021, 9:49 AM
Simba
Simba - avatar
+ 3
#include <iostream> using namespace std; int main() { //your code goes here int num; //cout <<"enter the number of passengers:\t"<<endl; cin>>num; int busSeats=50; int next_station=num%busSeats; int seats_free=busSeats-next_station; if(num>=50){ cout <<seats_free; } else{ cout<<50-num; } }
15th Jul 2021, 10:13 AM
Simba
Simba - avatar
+ 1
Yeah you nailed it. Thank you❤
15th Jul 2021, 10:16 AM
MOHAMED THOUFIC YOUSUF
0
What's the problem? Mentioned them
15th Jul 2021, 9:23 AM
Rohit
0
But they have shown that my code is not match with the expected output
15th Jul 2021, 10:09 AM
MOHAMED THOUFIC YOUSUF
0
F.MOHAMED THOUFIC YOUSUF No need to write if else. Just use modulus operator like: cout << 50 - num % 50;
15th Jul 2021, 11:08 AM
A͢J
A͢J - avatar
0
Ok bro. No no ok pro
15th Jul 2021, 11:17 AM
MOHAMED THOUFIC YOUSUF