Question: Problem: You have won a $ 1 0 0 gift certificate to buy your five favorite albums. The total cost of all albums must be

Problem: You have won a $100 gift certificate to buy your five favorite albums. The total cost of all albums must be $100 or less.
Modules Trying to Create:
1. main.
2. Calls inputAlbumCosts.
inputAlbumCosts. Uses a loop to input the costs of your five favorite albums. Accumulates the total cost as you input the price of each album.
3. Calls withinBudget.
withinBudget. Accepts the total cost of your albums and determines if you are within budget. Displays the total cost and displays a message indicating either that you are within budget or have exceeded $100 limit.
4. Calls averageCost.
averageCost. Accepts the total cost of the five albums. Calculates and displays the average cost of each album.
My Gaddis Pseudocode:
Module main()
Declare Real totalCost
Set totalCost =0
Call inputAlbumCosts(totalCost)
Call withinBudget(totalCost)
Call averageCost(totalCost)
End Module
Module averageCost (Real totalCost)
Declare Real average
Set average = totalCost /5
Display "The average cost of each album is: ", average
End Module
Module inputAlbumCosts (Real totalCost)
Declare Real albumCost
Declare Integer i
For i =1 To 5
Display "Enter the cost of the album i:"
Input albumCost
Set totalCost = totalCost + albumCost
End For
Call withinBudget(totalCost)
End Module
Module withinBudget (Real totalCost)
Display "The total cost is $: ", totalCost
If totalCost =100 Then
Display "This is within budget!"
Else
Display "You have exceeded the $100 budget!"
End If
Call averageCost(totalCost)
End Module
My Output:
Enter the cost of the album 1
7
Enter the cost of the album 2
87
Enter the cost of the album 3
8
Enter the cost of the album 4
9
Enter the cost of the album 5
7
The total cost is $: 0
This is within budget!
The average cost of each album is: 0
Output Trying to get:
Please enter the cost of album 1: 20.00
Please enter the cost of album 2: 12.00
Please enter the cost of album 3: 25.00
Please enter the cost of album 4: 8.00
Please enter the cost of album 5: 13.00
The total cost is $78
This is within budget!
The average cost of each album is 15.60.
Thank you for taking the time to read this long message. I am having trouble with my gaddis pseudocode getting the output I want. I have tried to rack my brain of what I did wrong in the code. How do I fix my gaddis pseudocode to get the output I am trying to get. I am missing something. The integer I and total value is not running the calculations. Thanks again.
Problem: You have won a $ 1 0 0 gift certificate

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!