Sunteți pe pagina 1din 3

Chris trimble

Unit 3 Assignment: Homework


5. What two things must you normally specify in a variable declaration?
Variables Name
Variables data type
6. What value is stored in uninitialized variables?
A variable that has been declared, but has not been initialized or
assigned a value.
3. Write assignment statements that perform the following operations with
the variables a, b, and c.
a. Adds 2 to a and stores the result in b
b=2+a
b. Multiplies b times 4 and stores the result in a
a=4*b
c. Divides a by 3.14 and stores the result in b
b = a / 3.14
d. Subtracts 8 from b and stores the result in a
a=b8
4. Assume the variables result, w, x, y, and z are all 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?
a. Set result = x + y
12
b. Set result = z * 2
4
c. Set result = y / x
2
d. Set result = y z
6
5. Write a pseudocode statement that declares the variable cost so it can hold real
numbers.
Declare Real cost
6. Write a pseudocode statement that declares the variable total so it can hold
integers. Initialize the variable with the value 0.
Declare Integer total = 0
7. Write a pseudocode statement that assigns the value 27 to the variable count.
Set count = 27
8. Write a pseudocode statement that assigns the sum of 10 and 14 to the variable
total.
Set total = 10 + 14
9. Write a pseudocode statement that subtracts the variable down Payment from
the variable total and assigns the result to the variable due.

Chris trimble
due = total - downPayment
10. Write a pseudocode statement that multiplies the variable subtotal by 0.15 and
assigns the result to the variable totalfee.
totalFee = subtotal * 0.15
6. Sales Tax
Design a program that will ask the user to enter the amount of a purchase.
The program should then compute the state and county sales tax. Assume the state
sales tax is 4 percent and the county sales tax is 2 percent. The program should
display the amount of the purchase, the state sales tax, the county sales tax, the
total sales tax, and the total of the sale (which is the sum of the amount of purchase
plus the total sales tax).
Hint: Use the value 0.02 to represent 2 percent, and 0.04 to represent 4
percent.
Constant Real stateTax = 0.04
Constant Real countyTax = 0.02
Display What is the amount of your purchase?
Input purchase
totalSalesTax = stateTax * countyTax
totalOfSale = (purchase * totalSalesTax) + purchase
Display
Display
Display
Display
Display

Today, your purchase was purchase


The state sales tax is stateTax
The county sales tax is countyTax
Your total sales tax is totalSalesTax
Your total today is totalOfSale

8. Tip, Tax, and Total


Design a program that calculates the total amount of a 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 percent tip and 7 percent sales tax. Display each
of these amounts and the total.
Display What was the total of your meal today?
Input meal
Constant Real salesTax = 0.07
Constant Real goodTip = 0.15
subTotal = (meal * salesTax) + meal
tipAmount = meal * goodTip
total = subTotal + tipAmount
Display Your meal cost $ meal
Display Your meal cost including tax is $ subTotal

Chris trimble
Display A 15% tip for your meal today would be $ tipAmount
Display Your total plus a 15% tip comes to $ total

S-ar putea să vă placă și