Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following variable declarations: int num1 = 10, num2 = 20, newNum = 30

ID: 3627184 • Letter: G

Question

Given the following variable declarations:

int num1 = 10, num2 = 20, newNum = 30;
double x = 5.0, y = 8.0;

Determine which of the following assignment statements are valid. For each invalid statement, explain why it is invalid. Assume that each statement immediately follows the above variable declarations.

a. num1 = 15;
b. num2 = num1 - 18;
c. num1 = 5; num2 = 2 + 6; num1 = num2 / 3;
d. num1 + num2 = newNum;
e. x = 12 * num1 - 15.3;
f. num1 * 2 = newNum;
g. x / y = x * y;
h. num2 = num1 % 2.0;
i. newNum = static_cast<int> (x) % 5;
j. x = x + 5;
k. newNum = num1 + static_cast<int> (4.6 / 2);

Explanation / Answer

num1 * num2 = newNum;

correct would be newNum= num1 * num2 ;

num1 * 2 = newNum + num2;

correct : num1 = newNum + num2; num1 = num1*2;

x / y = x * y;

correct : cannot be equated like this

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote