Watts-College / cpp-527-spr-2022

https://watts-college.github.io/cpp-527-spr-2022/
0 stars 1 forks source link

Lab 1 - Step 3 #10

Closed mmonakho closed 2 years ago

mmonakho commented 2 years ago

I was wondering why the code in Step 3 starts with "game". Where is it coming from? Step 1 had "a.game"...

open_goat_door <- function( game, a.pick )

Dselby86 commented 2 years ago

open_goat_door <- function( game, a.pick )

Is declaring a function named open_goat_door

That function will be looking for two arguments game and a.pick

When you use write the function you can use game and a.pick as variables in the function. But they exist for that function only.

So game is a separate variable than a.game.

I hope this helps

On Tue, Jan 18, 2022, 3:33 PM mmonakho @.***> wrote:

I was wondering why the code in Step 3 starts with "game". Where is it coming from? Step 1 had "a.game"...

open_goat_door <- function( game, a.pick )

— Reply to this email directly, view it on GitHub https://github.com/Watts-College/cpp-527-spr-2022/issues/10, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHB5SKVO62DKBVCSES3LUWXTB7ANCNFSM5MILDKTQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

mmonakho commented 2 years ago

It does, thank you!

mmonakho commented 2 years ago

Why didn't we put a.game or a.pick in brackets in Steps 1-2?

trioptre commented 2 years ago

@Dselby86

Can you clarify the sentence "That function will be looking for two arguments game and a.pick"?

Also, your sentence "When you use write the function you can use game and a.pick as variables in the function" - what does this mean?

Thanks, Dave

Dselby86 commented 2 years ago

Hi Dave,

When you create a function you declare the arguments that function is supposed to accept inside of the (). in this case "function(game, a.pick)". Then the function can use the values provided for the game and a.pick inside the function.

However, when you call the function you must provide values for game and a.pick.

So

test <- function(game, a.pick)

test(5, 6)

will assign 5 for game and 6 for a.pick.

You can also manually set the value of the arguments: test (a.pick = 6, game = 5)

But if you call the function without one of the required arguments it will return an error

test(5) # this won't work

Hope this helps.

On Tue, Jan 18, 2022 at 9:17 PM trioptre @.***> wrote:

@Dselby86 https://github.com/Dselby86

Can you clarify the sentence "That function will be looking for two arguments game and a.pick"?

— Reply to this email directly, view it on GitHub https://github.com/Watts-College/cpp-527-spr-2022/issues/10#issuecomment-1016066066, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHBZCMWZXCMBDW2LXIO3UWY3O7ANCNFSM5MILDKTQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Dselby86 commented 2 years ago

@mmonakho

That is just the way the code is written. You can have variables take on any name, but it is best to use something consistent that you and someone else can follow

mmonakho commented 2 years ago

Thank you!