Skip to Content
Learn
Code Challenge: C++ Functions
Water Plant

needs_water()

Instructions

1.

Define a function needs_water() that accepts:

  • An int number of days since the previous watering.
  • A bool value is_succulent. (A value of true would indicate that the plant is a succulent.)

Inside the function, you’ll need some conditional logic:

  • If is_succulent is false and days is greater than 3, return "Time to water the plant.".
  • If is_succulent is true and days is 12 or less, return "Don't water the plant!".
  • If is_succulent is true and days is greater than or equal to 13, 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.

Folder Icon

Take this course for free

Already have an account?