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
9 Answers
+ 1
How do you get 36 from 24 by subtraction? đ€
+ 1
Well, p - s*(p/s) is the same as p%s
0
forgot cout << empty; this is wrong
count << 50 - empty; this is right
0
You probably meant
station*(passenger / station)
0
oh wait im so dumb
thanks
0
đ
You're welcome đ
0
The description telling me to use % made me confused
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;
}
0
#include <iostream>
using namespace std;
int main() {
int a ;
int b ;
cin >> a ;
b = a % 50 ;
cout << 50 - b ;
return 0;
}