0

Question about Transportation(c++ Code Project)

#include <iostream> using namespace std; int main() { int station = 50; int passengers; cin >> passengers; int empty = passengers - station*(passengers % station); cout << empty; return 0; } What is wrong with the code? It keeps giving me negative answers If the input is 24, the output should be 36 but this doesn't

3rd Jun 2022, 2:24 PM
Noel K
9 Answers
+ 1
How do you get 36 from 24 by subtraction? đŸ€”
3rd Jun 2022, 2:32 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
Well, p - s*(p/s) is the same as p%s
3rd Jun 2022, 2:46 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
forgot cout << empty; this is wrong count << 50 - empty; this is right
3rd Jun 2022, 2:33 PM
Noel K
0
You probably meant station*(passenger / station)
3rd Jun 2022, 2:36 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
oh wait im so dumb thanks
3rd Jun 2022, 2:37 PM
Noel K
0
😄 You're welcome 🙂
3rd Jun 2022, 2:37 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
0
The description telling me to use % made me confused
3rd Jun 2022, 2:42 PM
Noel K
0
#include <iostream> using namespace std; int main() { int station = 50; int passengers,empty; cin>>passengers; if (passengers<50){ empty = 50-passengers;} else{ empty = (passengers % station);} cout << empty; return 0; }
3rd Jun 2022, 7:11 PM
Mihir Lalwani
Mihir Lalwani - avatar
0
#include <iostream> using namespace std; int main() { int a ; int b ; cin >> a ; b = a % 50 ; cout << 50 - b ; return 0; }
4th Jun 2022, 9:54 AM
ZAKI MAX
ZAKI MAX - avatar