# How To Build a Store Interface Program

> After the completion of one week, we were requested to build a store interface program that was the culmination of all we had learned throughout the first…

- Author: Bianca Correia
- Published: 2 Feb 2026
- Topics: ruby
- URL: https://biancacorreia.com/blog/how-to-build-a-store-interface-program

After the completion of one week, we were requested to build a store interface program that was the culmination of all we had learned throughout the first week. This included arrays, hashes, loops,blocks, conditionals, variables, gets.chomp and puts for output.

These on their own are quite straightforward but incorporating them all did present more of a challenge. The challenge was broken down in numerous steps which made it a little bit more digestible and enabled me to keep in top of the flow of the code and to better.

In this blog, I’ll walk through how to build a very simple supermarket-style program in Ruby. Something that lets a user see items for sale, choose what they want, and then get a total bill at the end. More importantly, it helped me understand how real systems (like online shops) might work behind the scenes, just in a much simpler way.

### Displaying a welcome message

```ruby
puts "> --------------------"
puts "> Welcome to Instacart"
puts "> --------------------"
```

Here we use `puts` to print text to the terminal.

This is purely for user experience. It makes the program feel like a real shop instead of just raw code. It also helps the user understand that the program has started. At first glance, this just looks like a list of items and prices. But conceptually, it acts like a tiny database. Each key is a product name, and each value is its price.

### Creating the Shopping Cart

```ruby
cart = []
```

The cart is an empty `array`.

Why an array?  
Because we want to store multiple items that the user chooses, like:

\["banana", "banana", "kiwi"\]

Each time the user selects something, we will push it into this cart array.

Defining the Store with a `Hash`

```ruby
store = {
"kiwi" => 1.25,
"banana" => 0.5,
"mango" => 4,
"asparagus" => 9
}
```

This is a hash, which stores key–value pairs:

Key → item name (string)

Value → price (number)

For example:

"banana" is the key

0.5 is the value

This makes it easy to look up prices later using:

```ruby
store["banana"]
```

Which would return: 0.5. It means: “Take the user’s input and use it as a key to fetch the price.” That’s a big conceptual leap as a beginner — I’m no longer just printing values, I’m now connecting user input to data structures. This also means all the prices live in one place. If I want to change the price of mango, I only need to change it in the hash, and the rest of the program still works. That’s something real systems rely on heavily.

### Displaying Items for Sale

```ruby
store.each do |item, price|
puts "> #{item}: £#{price}"
end
```

Here we use .each to loop through the hash.

For every item in the store, item holds the name (e.g. "kiwi") and price holds the price (e.g. 1.25). This prints something like:

kiwi: £1.25

banana: £0.5

mango: £4

asparagus: £9

So now the user can see what’s available before shopping.

### Preparing for User Input

```ruby
item = nil
```

We initialised item so it exists before the loop starts. This is important because we are about to use it in a loop condition.

### Creating the Shopping Loop

```ruby
until item == “quit”
```

This line is what makes the program feel “alive”.  
Instead of running once and stopping, the program keeps going until the user decides to quit.

This taught me that loops aren’t just for repeating actions — they allow the **user** to control the flow of the program. The code is waiting for human input and reacting to it. In a way, the program becomes a conversation. This helped me understand that software is often built around user behaviour, not just calculations.

### Asking the User for an Item

```ruby
puts "> Which item? (or 'quit' to checkout)"
item = gets.chomp
```

gets reads input from the user

`.chomp` removes the newline character at the end.

### Checking If the Item Exists

```ruby
if store.keys?(item)
```

This checks, is the user’s input one of the keys in the store hash?

For example: “banana” —> true, “pizza” —→ false

This prevents users from buying things that don’t exist.

### Adding Valid Items to the Cart

```ruby
cart < < items
```

If the item exists, we add it to the cart array. So the cart might look like:

\[“banana”, “mango”, “banana” \]

This allows duplicates, which is realistic for shopping.

### Handling Invalid Items

```ruby
elsif item != 'quit'
puts "sorry we don't have any #{item} today."
end
```

If the user types something that is not in the store and is not "quit", then we print an apology message. This introduces the idea of validation: never blindly trust user input. Instead of assuming the user will always type a valid product, the program verifies it against the data. So learning to guard against misspellings, unexpected values or mistakes that may be inputted early on is really useful.

### Printing the Bill

```ruby
puts '> -------BILL---------'
```

This marks the checkout stage of the program.

### Calculating the Total Price

```ruby
total_price = 0
cart.each do |item|

total_price += store[item]

end
```

We start with total\_price = 0, we loop through every item in the cart and for each item we look up the price in the store hash and add it to the total.

for example, —→ \["banana", "mango"\] becomes 0 + 0.5 + 4 = 4.5.

This taught me that loops aren’t just for printing — they’re for transforming data.  
Here, an array of strings becomes one meaningful number: the total cost. It also connects multiple concepts at once: looping through an array, accessing a hash and updating a variable. Which makes it a good mental workout as a beginner.

### Displaying the Final Total

```ruby
puts "> TOTAL: #{total_price} £"
puts "> --------------------"rub
```

This prints the final amount the user owes.

Example output: Total: 4.5£

This gives the program a proper ending and makes it feel complete.

I found that this store interface was a great beginner project because it felt practical and real. It simulates how real systems work: choosing products, validating input, and calculating totals. Beyond syntax,t his project taught me how arrays and hashes work together, user input connects to program login, data drives decisions and small programs can model real systems.

It was a great way to practice thinking in terms of data and flow rather than just individual lines of code.
