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!!!
10 Antworten
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;
}
+ 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;
}
+ 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
+ 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
0
Michaelangelo Garrison
Where is your attempts?
0
I didn't put them up because I got upset
0
Michaelangelo Garrison
Atleast you should show something otherwise noone will help you.
0
I appreciate it this is my first time putting up a post
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
0
#include <iostream>
using namespace std;
int main() {
int a;
cin >> a;
cout << 50 - a % 50;
return 0;
}
// Hope this helps