given the following variable declarations: Given the following variable declarat
ID: 3661646 • Letter: G
Question
given the following variable declarations: Given the following variable declarations: 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. For each of the following lines of variable declarations, identify it as valid or describe what makes the line invalid Write C++ statements that accomplish each of the following: Declare and initialize int variables x to 25 and y to 18 Declare and initialize an int variable temp to 10 and a char variable ch to 'A' Add 5 to the int variable x which already exists Declare and initialize a double variable payRate to 12.50.Explanation / Answer
2.
Invalid assignment
d) num1+num2 is a expression which will evaluate to some value,and we need a variable on the left side of the assignment operator(=).
f) same reason as above
g) same reason as above
h) we cant take modulus of an integer by a double value,we should use 2 instead of 2.0
rest all are valid..
3.
Line 1 is invalid because we have not declared n.Before assigning value to a variable we need to declare it like int n.We can declare and assign value at same time like int n=5;
Line 2 is invalid because in char letter= ; .we are trying to assign value to letter so it will try to assign letter to ; but it is not in qoutes.Correct way to represent a character is ';' and to end the expression we should put on more semi colon.
char letter=';' ;
Line 3 and 4 are valid.
4.
a. int x=25,y=18;
b. int temp=10;
char ch='A';
c. x=x+5;
d. double payRate=12.50;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.