+ 1

Can anyone help me to answer this?

I am a beginner in coding that's why I am facing a lot of issue in solving this problem. Each time I try it does not match the solution. 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. Please help!

15th Apr 2022, 12:07 PM
Amul Gaurav
Amul Gaurav - avatar
12 Respuestas
+ 1
Thanks a lot for your help bro but I competed the question just a few minutes ago. The solution is: #include <iostream> using namespace std; int main() { //your code goes here int passenger; cin>>passenger ; int bus=50 ; if(passenger < 50) { int empty_seats = bus - passenger ; cout<<empty_seats; } else if(passenger > 50) { int passenger_remaining = passenger % bus; int empty_seats1 = bus - passenger_remaining ; cout<<empty_seats1; } else { cout<<0; } return 0; } This is the very 1st question of coding in my life and I am extremely happy after solving this. I am trying for almost 5 hours for solving that and at last I did. Thanks for all your support!
15th Apr 2022, 1:46 PM
Amul Gaurav
Amul Gaurav - avatar
+ 5
See : #include <iostream> using namespace std; int main() { //your code goes here int passenger; cin>>passenger ; int bus=50; int passenger_remaining = passenger % bus ; cout<<passenger_remaining<<endl; int empty_seats = bus - passenger_remaining ; cout<<empty_seats<<endl; return 0; }
15th Apr 2022, 12:16 PM
Amul Gaurav
Amul Gaurav - avatar
+ 3
U welcome it doesn't necessarily have to be too long And always remember Google is your friend
15th Apr 2022, 1:49 PM
Olufikayomi Jetawo
+ 2
Task is asked to output only empty seats.. Don't output passenger_remaining..
15th Apr 2022, 12:42 PM
Jayakrishna 🇮🇳
+ 2
#include <iostream> using namespace std; int main() { //your code goes here int a; int b = 50; cin>>a; int seatLeft = 50 - a%50; cout<< seatLeft ; return 0; } Make use of d modulus operation
15th Apr 2022, 1:42 PM
Olufikayomi Jetawo
+ 2
Yes but this is 1st question of my coding journey and practice makes the man perfect.
15th Apr 2022, 1:50 PM
Amul Gaurav
Amul Gaurav - avatar
+ 1
Oh okay! That's the mistake 😕 Thanks a lot for a great advice.
15th Apr 2022, 12:43 PM
Amul Gaurav
Amul Gaurav - avatar
+ 1
Amul Gaurav Good that you have already first and shorter versions of codes, in first attempt. The compiler above you posted is difficult to use in mobile. May be i don't know how to use it.. All online compilers are difficult to use in mobile. I need to type a lot, stil not work. The code is fine. Then don't use underrated compiler in first use. You have sololearn which can help write all type of programs except gui supported.. So use sololearn.. Forget about online compilers.. I don't have pc, I use Sololearn... Hope it helps..
15th Apr 2022, 2:20 PM
Jayakrishna 🇮🇳
+ 1
If you are a biginner, try starting off with an easier language like html (markup lang) then python then js then your choice 🙂 Good luck on your coding journey! 🙂
16th Apr 2022, 7:19 AM
Chris
Chris - avatar
+ 1
Yes, you are absolutely right from your side and I appreciate that. But in India most of companies don't allow us to write code in python. And they ask questions in interviews from DSA and Algorithms, that's why I had two choices: 'Java or C++' , and I chose C++ because I don't have laptop due to some reasons and Java is used for app development which requires a medium type laptop but now I can only afford a basic laptop like i3. And you said HTML, I wanna say that after C++, I will learn HTML for web development.
16th Apr 2022, 9:05 AM
Amul Gaurav
Amul Gaurav - avatar
+ 1
I really advise you not to see the answer of any problem. u can just ask for a hint and try it yourself. if it takes too long then look at the code.
16th Apr 2022, 7:36 PM
آلاء صلاح
آلاء صلاح - avatar
0
Can you help me again please. I write a code in 'gdb' compiler in my smartphone because I don't have laptop now. The code is: #include<iostream> using namespace std; int main() { int p; cin>>p; int bus=50; int p1=p%bus; int p2=bus-p1; cout<<p2; return 0; } Every time I try to input integer value like '160' it takes a very big value on its , I don't know how this is happening. Please jayakrishna run this code in gdb compiler and figure out this problem, it helps me a lot. Link of gdb compiler is below: https://www.onlinegdb.com/online_c++_compiler
15th Apr 2022, 12:54 PM
Amul Gaurav
Amul Gaurav - avatar