Tea House

Tea House in Seoul, South Korea

A tea house in Seoul, South Korea

Problem to Solve

Tea is the most popular drink in the world—after, of course, water!

In a program called teahouse.R, in a folder called teahouse, write a program to recommend users a cup of tea that will be… well, their cup of tea.

Demo

Getting Started

For this problem, you’ll need to create teahouse.R in a folder called teahouse.

Create teahouse.R

Open RStudio per the linked steps and navigate to the R console:

>

Next execute

getwd()

to print your working directory. Ensure your current working directory is where you’d like to create this problem’s folder. If using RStudio through cs50.dev the recommended directory is /workspaces/NUMBER where NUMBER is a number unique to your codespace.

If you do not see the right working directory, use setwd to change it! Try typing setwd("..") if in the working directory of another problem, which will move you one directory higher.

Next execute

dir.create("teahouse")

in order to create a folder called teahouse in your codespace.

Now type

setwd("teahouse")

followed by Enter to move yourself into (i.e., open) that directory. Your working directory should now end with

teahouse/

Finally, type

file.create("teahouse.R")

to create a file called teahouse.R inside of the teahouse folder.

If all was successful, you should execute

list.files()

and see teahouse.R. If not, retrace your steps and see if you can determine where you went wrong!

Specification

This problem is composed of two parts. In the first part, you’ll write teahouse.R. In the second, you’ll write a program of your choice.

Part 1: teahouse.R

Tea Diagram

Tea varies along many dimensions. Consider two for the sake of this problem: flavor and caffeine.

In teahouse.R, write a program that prompts a user twice: first for their taste in flavor, and second for their preference for caffeine. Then, recommend teas based on the following logic:

  • Recommend green tea if a user prefers caffeine and a light flavor.
  • Recommend black tea if a user prefers caffeine and a bold flavor.
  • Recommend chamomile tea if a user prefers no caffeine and a light flavor.
  • Recommend rooibos tea if a user prefers no caffeine and a bold flavor.

A user should enter either “Light” or “Bold” for their taste in flavor and “Yes” or “No” for their preference for caffeine. If a user does not enter a valid choice for either one, do not recommend a tea: instead, remind them of the proper inputs.

Part 2: Setting Up Shop

Think about a beverage you particularly enjoy (or perhaps a type of food!). In the same folder as teahouse.R, write a program to recommend various types of that beverage or food based on input from the user. Be as creative as you’d like: the only requirement is that you’re excited about your choice!

Usage

Assuming teahouse.R is in your working directory, enter the below in the R console to test your program:

source("teahouse.R")

How to Test

Here’s how to test your code from Part 1 manually:

  • Run your program with source("teahouse.R"). Type “Light,” followed by “Yes.” Your program should output a phrase to recommend “green tea.”
  • Run your program with source("teahouse.R"). Type “Bold,” followed by “Yes.” Your program should output a phrase to recommend “black tea.”
  • Run your program with source("teahouse.R"). Type “Light,” followed by “No.” Your program should output a phrase to recommend “chamomile tea.”
  • Run your program with source("teahouse.R"). Type “Bold,” followed by “No.” Your program should output a phrase to recommend “rooibos tea.”
  • Run your program with source("teahouse.R"). Type “Medium,” followed by “Yes.” Your program should remind the user of the options for flavor.
  • Run your program with source("teahouse.R"). Type “Light,” followed by “Maybe.” Your program should remind the user of the options for caffeine.

Test your code from Part 2 in a similar way, with inputs that make sense for your program.

check50

You can also check your code using check50, a program that CS50 will use to test your code when you submit. But be sure to test it yourself as well!

Run the following command in the RStudio console:

check50("cs50/problems/2024/r/teahouse")

Green smilies mean your program has passed a test! Red frownies will indicate your program output something unexpected. Visit the URL that check50 outputs to see the input check50 handed to your program, what output it expected, and what output your program actually gave.

How to Submit

You can submit your code using submit50.

Keeping in mind the course’s policy on academic honesty, run the following command in the RStudio console:

submit50("cs50/problems/2024/r/teahouse")