If productCost and productPrice are numeric variables, and productName is a stri
ID: 3758465 • Letter: I
Question
If productCost and productPrice are numeric variables, and productName is a string variable, which of the following statements are valid assignments? If a statement is not valid, explain why not.
productCost=100
productPrice=productCost
productPrice=productName
productPrice=”24.95”
15.67=productCost
productCost= $1,345.52
productCost = prodcutPrice – 10
prodcutName = “mouse pad”
productCost + 20 = productPrice
prodcutName = 3-inch nails
prodcutName = 43
prodcutName = “44”
“99” = prodcutName
prodcutName = brush
Explanation / Answer
productCost=100 //Valid statement. 100 will be assigned to productCost.
productPrice=productCost //Valid statement. The value in productCost will be copied to productPrice.
productPrice=productName //Invalid statement. productName is a variable of type string, and it cannot be assigned to an integer variable.
productPrice=”24.95” //Invalid statement. productPrice is a variable of type integer, and a string cannot be assigned.
15.67=productCost //Invalid statement. Left side value should be a variable.
productCost= $1,345.52 //Invalid statment. $ is not a numeric value and its not allowed to be assigned to numeric variable.
productCost = prodcutPrice – 10 //Valid statement. 10 will be subtracted from productPrice and the result will be assigned to productCost.
prodcutName = “mouse pad” //Valid statement. A string is being assigned to a string variable.
productCost + 20 = productPrice //Invalid statment. Left side of = should be a variable, and not an expression.
prodcutName = 3-inch nails //Invalid statement. String should be either in double quotes, which is string constant, or a variable also of type string. The left hand side value is neither.
prodcutName = 43 //Invalid statement. Same reason as stated for the previous statement.
prodcutName = “44” //Valid statement. A string constant "44" is assigned to the string variable productName
“99” = prodcutName //Invalid statement. Leftside of = should be a variable. Its a constant which is not allowed.
prodcutName = brush //Invalid statement, unless brush is declared a string variable.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.