You must specify the variable type and an identifier. int n; // type - int, identifier - n 6. What value is stored in uninitialized variables?
Some languages assign a default value as 0 to uninitialized variables. In many languages, however, uninitialized variables hold unpredictable values.
Algorithm Workbench
3. Write assignment statements that perform the following operations with the variables a, b, and c.
Adds 2 to a and stores the result in b.
Multiplies b times 4 and stores the result in a
Divides a by 3.14 and stores the result in b
Subtract 8 from b and stores the result in a
4. Assume the variables result, w, x, y , and z are integers, and that w=5, x=4, y=8, and z=2. What value will be stored in result in each of the following statements?
Set result = x + y
Set result = z* 2
Set result = y / x
Set result = y – z
5. Write a pseudocode statement that declares the variable cost so it can hold real number.
6. Write a pseudocode statement that declares the variable total so it can hold real integers. Initialize the variable with the value 0.
7. Write a pseudocode statement that assigns the value of 27 to the variable count.
8. Write a pseudocode statement that assigns the sum of 10 and 14 to the variable total.
9. Write a pseudocode statement that subtracts the variable Down Payment from the variable total and assigns the result to the variable due.
10. Write a pseudocode statement that multiplies the variable subtotal by 0.15 and assigns the result to the variable total fee.
Programming Exercises
6. Sales Tax 8. Tip, Tax, and Total
Design a program that calculates the total amount of meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15% tip and 7% sales tax. Display each of these amounts and the total.