CMPSC 201 - Ch. 3 Worksheet #1 | Name - |
1. List a valid and logical variable name for a variable that would store the total price of a customer's purchase before taxes. Make sure that you also follow the conventions discussed in class such as beginning a variable name with a lowercase letter and beginning successive words with a capital letter.
2. Write a declaration statement that declares an int variable named numApples and intializes it to the value zero.
3. Write an assignment statement that assigns the value 10 to the variable numApples.
4. Write an assignment statement that adds 5 to the value stored in numApples and assigns the resulting sum to the variable totalApples.
5. Write an assignment statement that subtracts 3 from the value stored in numApples and assigns the result back into the variable numApples.
6. Write the same assignment statement as in #5 above using the -= compound operator.
7. Write an assignment statement that adds one to the variable numApples using the incrementing operator.
8. Write a full C++ program that declares integer (int)
variables named total, wins, losses, and ties and initializes
each one to the value of 0. Then, include 3 separate assignment statements that
assign different integer value to the variables wins, losses, and ties. You can make up integer values of your choice. Finally, write another assignment
statement that assigns the sum of these three variables to the variable total.
The program should then display an output message in the following format where the 15 in this example is replaced with the actual value of the
variable total
The total wins, losses, and ties is 15