C++: "Transportation" Test
I don't know why this code won't work. (Assume that x=231. And please look carefully.) #include <iostream> using namespace std; int main() { //your code goes here int x; int y=50; int z=y-(x%y); cin>>x; if (x<=y){ cout<<y-x<<endl; } else{ cout<<y-(x%y); } return 0; } At first, I used the Z value in the "else" curly brackets, but then since that didn't work, I typed out the whole thing instead. It worked this time. So why didn't Z's value (which is the exact same thing) work with 231, but typing out its full value did? Edit: Sorry, okay, I was pretty confused at first as to what I had to do, so I ended up using if...else since that was the first thing that came to mind.