Design&Pseudocode V2
Design&Pseudocode V2
Pseudocode solution:
Display “Enter the three numbers:”
Read the three numbers into variables x, y, and z
Let the variable sum = x + y + z
Let the variable average = sum/3.0
Display “The average value = ” and average
Problem 2: Prompt for and enter the price of an item being
purchased at a retail store and calculate and display the final
price including sales tax. Assume the sales tax is 6.5%.
Pseudocode solution:
Display “Enter the price:”
Read the price into the variable price
Let the variable tax = 0.065 * price
Let the variable total = price + tax
Display “The final price with sales tax = $” and total
Problem 3: A cubic foot of water weighs 62.4 pounds and
contains 7.48 gallons. Prompt for and enter a number of cubic
feet of water and then calculate and display the water’s weight in
pounds and its amount in gallons.
Pseudocode solution:
Display “Enter the number of cubic feet of water:”
Read the number of cubic feet of water into the variable
volume
Let the variable weight = volume * 62.4
Let the variable gallons = volume * 7.48
Display “Water weight in pounds =” and weight
Display “Water amount in gallons =” and gallons
Problem 4: Prompt for and read a test score (integer values in
the range 0-100) and then determine and display if the score is
passing (60 or more). Note: This solution requires an if selection
structure – we will learn more about this structure later in the class.
Pseudocode solution:
Display “Enter the score:”
Read the score into the variable score
If score > 60
display “The score is passing”
Problem 5: Prompt for and read two integers and then determine
and display the smaller of the two integers (assume the numbers
are different). Note: This solution requires an if-else selection
structure – we will learn more about this structure later in the class.
Pseudocode solution:
Display “Enter two integers:”
Read the numbers into the variables x and y.
If x < y
let the variable smaller = x
else
let the variable smaller = y
Display “The smaller number =” and smaller
Problem 6: Prompt for and enter 30 numbers and find and
display their average. Note: This problem is similar to Problem 1.
But, it is not practical to use 30 different variables here for the
numbers, so the solution given here uses a looping structure – we will
learn more about this structure later in the class.
Pseudocode solution:
Initialize the variable sum = 0.
Initialize the variable counter = 1.
While counter < 31
Display “Enter a number:”
Read the number into the variable x
Let sum = sum + x
Let counter = counter + 1
End of while loop
Let the variable average = sum/30.0
Display “The average value =” and average
Problem 7: Prompt for and enter 40 test scores (integer values in
the range 0-100), and count and display how many were passing
scores (60 or more) and how many failing scores (59 or less).
Note: This problem will require using an if-else selection structure
inside of a looping structure. We will cover these topics in more detail
later in the class.
Pseudocode solution:
Initialize the pass variable for counting the number of
passes to 0
Initialize the fail variable for counting the number failures to
0
Initialize the variable counter = 1
While counter < 41
Display “Enter a test score:”
Read the test score into the variable score.
If score > 59
pass = pass + 1
else
fail = fail + 1
Let counter = counter + 1
End of while loop
Display “Number of passing grades is” and pass
Display “Number of failing grades is” and fail