0

C++ 11 code project (first project)

Hello I keep getting this as wrong but i am getting the right answer.. I have put the C++ shell link that i am using and posted it down below. What am I missing? http://th.cpp.sh/2wp6x #include <iostream> using namespace std; const int bus_limit = 50; int main() { cout << "Bus Passenger Calculator\n" << endl; int passengers; cout << "Enter how many passengers:\t"; cin >> passengers; int leftover; int lastbus; leftover = passengers - bus_limit; lastbus = abs(leftover) % 50; cout << lastbus; return 0; }

2nd Oct 2022, 3:55 PM
Jennifer Lea Bonds
Jennifer Lea Bonds - avatar
4 Answers
+ 2
Sample input : 126 126-50=76 76%50 = 26 but Correct answer is 24. Rethink logic.. For Code project : there expects only required answer, not less or more character on output. Your code prints "Bus..." "Enter how... : " 26 But expected output is just : 24
2nd Oct 2022, 4:07 PM
Jayakrishna🇮🇳
Jayakrishna🇮🇳 - avatar
+ 1
Like this ? It still saying it is wrong for the answer. I found an answer, but I am wondering what I am missing It seems like I am missing up my logic.. What am I missing >_< #include <iostream> using namespace std; const int bus_limit = 50; int main() { cout << "Bus Passenger Calculator\n" << endl; int passengers; cout << "Enter how many passengers:\t"; cin >> passengers; int leftover; int lastbus; leftover = abs(passengers) % bus_limit; lastbus = bus_limit - leftover; cout << lastbus; return 0; } cpp.sh/2nbgz
2nd Oct 2022, 4:30 PM
Jennifer Lea Bonds
Jennifer Lea Bonds - avatar
+ 1
Yes. It works fine. You can save code in Sololearn and share link here.. Where are you trying this? As I said, if it is in code coach then comment your first 2 couts. Then check..
2nd Oct 2022, 6:01 PM
Jayakrishna🇮🇳
Jayakrishna🇮🇳 - avatar
+ 1
I got it thanks
3rd Oct 2022, 1:55 PM
Jennifer Lea Bonds
Jennifer Lea Bonds - avatar