Tea House
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 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/2025/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.
Due to the open-ended nature of Part 2, your second program cannot be checked by check50
.
How to Submit
After you submit, be sure to check your autograder results. If you see SUBMISSION ERROR: missing files (0.0/1.0)
, it means your file was not named exactly as prescribed (or you uploaded it to the wrong problem).
Correctness in submissions entails everything from reading the specification, writing code that is compliant with it, and submitting files with the correct name. If you see this error, you should resubmit right away, making sure your submission is fully compliant with the specification. The staff will not adjust your filenames for you after the fact!
In RStudio, select both teahouse.R
and your .R
program from Part 2, as by checking the box to the left of the files’ names. With the file selected, click on the icon at the top of the file explorer. Choose Export, name your file
teahouse-solution.zip
, followed by Download.
Go to CSCI E-5a’s Gradescope page.
Click Problem Set 2: Tea House.
Unzip your teahouse-solution.zip
file. Open the folder. Drag and drop your .R
files to the area that says Drag & Drop. Be sure that your .R
files are correctly named exactly as prescribed above, lest the autograder fail to run on your submission! Note that your submission is considered incomplete if any of the files are missing—be sure they’re all there!
Click Upload.
You should see a message that says “Problem Set 2: Tea House submitted successfully!”
Be sure to double-check your autograder results before moving on!