0

need help with the c++ basic concept project

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. I don't know what i missed or what im doing wrong please help!!!

10th May 2021, 3:42 AM
Michaelangelo Garrison
Michaelangelo Garrison - avatar
10 odpowiedzi
0
🅰🅹 🅐🅝🅐🅝🅣 and Michaelangelo Garrison This is my answer, please mention the errors if any occured in this program. #include <iostream> using namespace std; int main() { int p; cin>>p; while(p>=50) { p=p-50; } if(p==0) cout<<p; else cout<<(50-p); return 0; }
10th May 2021, 4:26 AM
Akash Singh
Akash Singh - avatar
+ 1
Akash Singh No need to use loop here. You can just do in one line 50 - p % 50 #include <iostream> using namespace std; int main() { int p; cin>>p; cout << (50 - p % 50); return 0; }
10th May 2021, 5:01 AM
A͢J
A͢J - avatar
+ 1
I think that's what the lesson wanted me to do I have a problem with overthinking it thank you again for your help that project was really getting the best of me
10th May 2021, 5:03 AM
Michaelangelo Garrison
Michaelangelo Garrison - avatar
+ 1
#include <iostream> using namespace std; int main() { //your code goes here int num,num2; cin>>num; if(num<=50){ cout<<50-num; }else if(num>50){ num2=num%50; cout<<50-num2; } return 0; } //each if statments explain the concepts
10th May 2021, 6:05 AM
Alto
Alto - avatar
0
Michaelangelo Garrison Where is your attempts?
10th May 2021, 3:43 AM
A͢J
A͢J - avatar
0
I didn't put them up because I got upset
10th May 2021, 3:53 AM
Michaelangelo Garrison
Michaelangelo Garrison - avatar
0
Michaelangelo Garrison Atleast you should show something otherwise noone will help you.
10th May 2021, 3:56 AM
A͢J
A͢J - avatar
0
I appreciate it this is my first time putting up a post
10th May 2021, 4:09 AM
Michaelangelo Garrison
Michaelangelo Garrison - avatar
0
I really appreciate it I understand my problem I didn't have while or if else statements I didn't know that was needed for this problem
10th May 2021, 4:44 AM
Michaelangelo Garrison
Michaelangelo Garrison - avatar
0
#include <iostream> using namespace std; int main() { int a; cin >> a; cout << 50 - a % 50; return 0; } // Hope this helps
12th May 2021, 2:09 AM
Calvin Thomas
Calvin Thomas - avatar