+ 1

help with the first C ++ "transport" problem

#include <iostream> using namespace std; int main() { int a; int b=50; int c; int d; int e; cin>>a; if (a<b){ e=b-a; }else if (a>b){ c=a-b; d=c-b; e=b-d%b; }else{ e=0; } cout<<e<<endl; return 0; } why a test case is not right, what did I do wrong? (the test case is the third, the hidden one)

21st May 2021, 2:26 PM
Francesco Famosi
Francesco Famosi - avatar
3 Réponses
+ 7
Your code is giving wrong output if 50 < a < 100. For that, you can remove variable d and use variable c instead. //int d //d=c-b; e=b-c%b;
21st May 2021, 3:43 PM
Simba
Simba - avatar
+ 3
#include <iostream> using namespace std; int main() { int no,x; cin>>no; cout<<50-(no%50); return 0; }
21st May 2021, 3:45 PM
Hrutik Bhalerao
Hrutik Bhalerao - avatar
+ 2
thank you all
21st May 2021, 4:06 PM
Francesco Famosi
Francesco Famosi - avatar