Home Improvements

Write a program that calculates the cost of all home improvements. The program should ask the user how many rooms they want to upgrade in their house. For each room, the user is asked to enter the cost of flooring, paint, and furniture. The total cost for each room is calculated and stored in an array. After all data is entered, the program displays the total spent on each room, the total overall cost of home improvements, and calculates the average cost per room rounded to two decimal places.

How many rooms are you upgrading? 3

Room 1
Enter flooring cost: £1200
Enter paint cost: £110
Enter furniture cost: £380

Room 2
Enter flooring cost: £1000
Enter paint cost: £110
Enter furniture cost: £250

Room 3
Enter flooring cost: £850
Enter paint cost: £90
Enter furniture cost: £250

Room 1 cost: £1690.0
Room 2 cost: £1360.0
Room 3 cost: £1190.0
Average cost per room: £1413.33
Total cost of home improvement: £ 4240.0
DECLARE numRooms AS INTEGER
DECLARE flooring, paint, furniture, total, average AS REAL
DECLARE roomTotals[numRooms] AS REAL

SEND "How many rooms are you upgrading?"
RECEIVE numRooms

SET total TO 0
DECLARE roomTotals[numRooms] AS REAL

FOR i FROM 0 TO numRooms - 1 DO
    SEND "Room", i + 1

    SEND "Enter flooring cost: £"
    RECEIVE flooring

    SEND "Enter paint cost: £"
    RECEIVE paint

    SEND "Enter furniture cost: £"
    RECEIVE furniture

    SET roomTotals[i] TO flooring + paint + furniture
    SET total TO total + roomTotals[i]
END FOR

SET average TO ROUND(total / numRooms, 2)

FOR i FROM 0 TO numRooms - 1 DO
    SEND "Room", i + 1, "cost: £", roomTotals[i]
END FOR

SEND "Average cost per room: £", average
SEND "Total cost of home improvement: £", total
num_rooms = int(input("How many rooms are you upgrading? "))

room_totals = [float] * num_rooms
total = 0

for i in range(num_rooms):
    print()
    print("Room", i + 1)

    flooring = float(input("Enter flooring cost: £"))
    paint = float(input("Enter paint cost: £"))
    furniture = float(input("Enter furniture cost: £"))

    room_totals[i] = flooring + paint + furniture
    total = total + room_totals[i]

average = round(total / num_rooms, 2)

print()
for i in range(num_rooms):
    print("Room", i + 1, "cost: £" + str(room_totals[i]))

print("Average cost per room: £" + str(round(average, 2)))
print("Total cost of home improvement: £", str(round(total, 2)))
# Ask how many rooms will be upgraded
num_rooms = int(input("How many rooms are you upgrading? "))

# Array to store total cost for each room
room_totals = [float] * num_rooms
total = 0

# Loop for each room
for i in range(num_rooms):
    print()
    print("Room", i + 1)

    flooring = float(input("Enter flooring cost: £"))
    paint = float(input("Enter paint cost: £"))
    furniture = float(input("Enter furniture cost: £"))

    # Total cost for the room
    room_totals[i] = flooring + paint + furniture
    total = total + room_totals[i]

# Calculate average cost per room
average = round(total / num_rooms, 2)

# Display results
print()
for i in range(num_rooms):
    print("Room", i + 1, "cost: £" + str(room_totals[i]))

# Display the average and total
print("Average cost per room: £" + str(round(average, 2)))
print("Total cost of home improvement: £", str(round(total, 2)))

Extension

Extend the program to include the following:

  • Input validation so the user must choose at least 1 room.
  • Running totals for flooring, paint and furniture.
    • Totals should be displayed for each at the end of the program.
  • If over £2500 is spent, the user should be informed of a 10% discount.
    • This should then be applied at the end of the program.
  • There is a 1 in 10 chance to get a room for free.
    • At the end of the program, generate a number between 1 and 10.
    • If that number is 1, then tell the user they are a winner.
      • Pick a room at random, and remove that price from the final bill.
    • If the number is not 1, let the user know they didn’t win.

Target

You should be able to use 1-D Arrays to solve a problem.