OK, this is my first programming class, ever. I have no prior knowledge AT ALL.
ID: 3542085 • Letter: O
Question
OK, this is my first programming class, ever. I have no prior knowledge AT ALL. I'm taking this class online, I went to see the instructor yesterday and she was no help whatsoever.
I am very confused regarding string variables vs string constants; numeric variables vs numeric constants. The main source of my confusion is my textbook: Programming Logic and Design Comprehensive, 7th ed. At the end of chapter 2 it has a list of definitions, and it clearly states a string constant must be enclosed within quotation marks. It defines string variable as letters, digits, and special characters such as punctuation marks.
So this means that if something is in quotes, its a string constant, right? Eh, no. I guess.
Here's the problem I went to see her about (btw the problem is already on this site but not answered completely, nor is it answered correctly)
I put the answers I think are right. PLEASE HELP, and also, PLEASE TELL ME why I'm wrong if you see something incorrect.
If productCost and productPrice are numeric variables, and productName is a string variable, which of the follwoing statements are valid assignments? If it's not valid, state WHY NOT..
a. productCost = 100 (valid)
b. productPrice = productCost (valid)
c. productPrice = productName (not valid, productPrice must be numeric, productName is string)
d. produtctPrice = "24.95" (not valid, productPrice only stores numeric data)
f. prodcutCost = $1,345.52 (not valid, productCost only stores numeric data)
g. productCost = productPrice - 10 (i THINK this one is valid, numeric variables can do mathematic operations)
h. productName = "mouse pad" (I thought it was not valid, because I thought quotes made it a string constant, not a string variable, so now I don't know)
i. productCost + 20 = productPrice (not valid, order is wrong)
j. productName = 3-inch nails (valid)
k. productName = 43 (not valid because it would work (this according to my instructor))
l. productName = "44" (valid) (but i dont understand why it is, if K isn't - thought the quotes didn't matter?)
n. productName = brush (valid)
p. productPrice = productPrice (not valid, numeric variables can only contain digits)
q. productName = productCost (she said not valid, but WHY?)
I know this is long, but PLEASE HELP!! Thank you!
Explanation / Answer
h.productName = "mouse pad"(valid,because string variable can have " " value)
I.productName = "44" (valid,you can assign sting variable such values)
p. productPrice = productPrice(valid,because data type of both are same)
q.productName = productCost(not valid,because data type of both are not same)
sorry i cant understand "k".. what was your doubt in that??
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.