I wrote this function and it was working perfectly fine and then i came back a few days later and when i ran it the result wont show in the console like it used to before. I didn't change a single thing. Any insight would be greatly appreciated.
Grade_Analyzer <- function(S, R, P, B)
{
PB <- P+B
SB <- S+B
if(S < P)
{
print("The highest possible score you can get is P + B:")
It looks like a closing bracket was left off for the scenario if(S == P). If you add a } before if(S > P) and eliminate the second-to-last } #end IF line in your function, I believe it will work as intended. I made these changes in the condensed version below, adding comments where the two changes were made.
Grade_Analyzer <- function(S, R, P, B) {
PB <- P+B
SB <- S+B
# scenario 1
if(S < P) {
print("The highest possible score you can get is P + B:")
print(PB)
if(R == PB) {
new_score <- PB
print("score 1")
return(new_score)
} else if(R < PB) {
print("score 2")
return(R)
} else if(R > PB) {
print("score 3")
return(PB)
} else {
print("score 4")
return(R)
}
}
# scenario 2
if(S == P) {
if(R == SB) {
print("score 5")
return(SB)
} else {
print("score 6")
return(R)
}
} # newly added bracket
# scenario 3
if(S > P) {
print("score 7")
return(S)
}
# } #end if -THIS IS REMOVED
} # End Function
P <- 22
B <- 30
S <- 54
R <- 67
Grade_Analyzer(S,R,P,B)
#> [1] "score 7"
#> [1] 54