Given the following variable declarations: int num1 = 10, num2 = 20, newNum = 30
ID: 3627202 • 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
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.