Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercise 8 Submission - Ellingsen #13

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions GuessMyNumberGame.Rscript.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
##Guess My Number

###A game that allows user to guess a randomly generated number and gives feedback
###for correct and incorrect guesses.

#Generate a random number between 1 and 100

range <- 1:100
randonumber <- sample(range, i)

# Write a for loop that allows a user to guess up to ten times
# Output 'Lower' if guess is greater than random number
# Output 'Higher' if guess is less than random number
# Output 'Correct!' if user guesses random number

for (i in 1:10) {
guess <- readline(prompt = "Guess:")
guess <- as.integer(guess)
if (guess > randonumber){
print("Lower")
} else if (guess < randonumber){
print("Higher")
} else {
print("Correct!")
break
}
}
26 changes: 26 additions & 0 deletions UWvMSU_Summary.Rscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#Parse score data for each team
data <- read.table("UWvMSU_1-22-13.txt",header = TRUE, stringsAsFactors = FALSE)
UWscores <- data[data$team=="UW",]
MSUscores <- data[data$team=="MSU",]

#Create cummulative totals for each team
UWtotal <- numeric(length(UWscores$score))
for(row in 1:length(UWscores$score)){
UWtotal[row] <- sum(UWscores$score[1:row])
}

MSUtotal <- numeric(length(MSUscores$score))
for(row in 1:length(MSUscores$score)){
MSUtotal[row] <- sum(MSUscores$score[1:row])
}

# Assign cummulative scores and totals to coordinates and plot on one graph
x1 <- UWscores$time
y1 <- UWtotal
x2 <- MSUscores$time
y2 <- MSUtotal
plot(x1,y1,type = "l", pch=19, main = "UW vs. MSU Basketball
1-22-13", col="red", xlab = "Time (min)", ylab = "Score")
lines(x2,y2, pch=18, col="blue", type = "l", lty=2)
legend(25, 15, legend=c("UW", "MSU"), col=c("red","blue"), lty = 1:2, cex = 0.8)