vendredi 20 mars 2020

If... else versus if.... else if

I am working through an assignment and I am confused about what the question is asking/allowing me to use. DATA AMD "Return is 5%" GE "Return is 1% Anything else "Not in your portfolio"

The instructions state to use if... else for part A and to use if... else if for part B Here is my code for reference

Part A

mystock <- "GE"
if (mystock == "AMD")
  {print ("Return is 5%")} else (mystock == "GE")
{print ("Return is 1%")} 

Part B

mystock <- "GE"

if (mystock == "AMD") {print ("Return is 5%")} 
else if (mystock == "GE") {
      print ("My return is 1%")} 
else if(mystock != "AMD") {
      print ("Not in your portfolio")} 
else if (mystock != "GE") {
      print ("Not in your portfolio")}

I think Part B is correct per instructions, I am not sure how to add a third arguement into Part A and still be compliant with instructions.

If someone could point me in the right direction that would be great.

Aucun commentaire:

Enregistrer un commentaire