Learn
Code Challenge: C++ Functions
Water Plant
needs_water()
Instructions
1.
Define a function needs_water()
that accepts:
- An
int
number ofdays
since the previous watering. - A
bool
valueis_succulent
. (A value oftrue
would indicate that the plant is a succulent.)
Inside the function, you’ll need some conditional logic:
- If
is_succulent
isfalse
anddays
is greater than3
, return"Time to water the plant."
. - If
is_succulent
istrue
anddays
is12
or less, return"Don't water the plant!"
. - If
is_succulent
istrue
anddays
is greater than or equal to13
, return"Go ahead and give the plant a little water."
. - Otherwise, return
"Don't water the plant!"
.
Note: Don’t print the strings; return them from the function.