Hey guys I am having trouble on how to solve this code. Please give me the steps on how to solve. I need to figure out what the out put is with out having to run it in my dev c++ program:
int x = 5;
int y = 12;
if (x + y > 20 || y - x < 10)
{
x = y + 6;
y = 2 * (x + y);
cout << x << " " << y << " " << x - y << " " << x + y << endl;
}
else
{
y = (5 * x + 20) % y;
cout << x << " " << y << " " << x * x + y * y << endl;
}
This should be just like working through any normal math/algebra problem. Go all caveman and grab yourself a pen & some paper, & just substitute numbers where the variables are used. Work out how each expression will evaluate line-by-line & hey-presto! you will now be able to think like a computer.
like @Norm said take a piece of paper and write value of x and y for each line. Check if there is assignation or comparison. Like algebra () , * and / are higher priority than + and - . = calculates the right operand and assign it to the left operand.