CJCoding With Joseph
15free / daySign inCreate account

Mastering C++

Function Practice Questions

Understand Functions

These questions are based on the lessons from the textbook and are designed to help you practice writing and using functions in C++. Once you finish, make a post in the community with your .cpp file included to get peer feedback.


Question 1

Create a function called welcome that doesn't return anything and doesn't take any parameters.

Inside the function, print this message: Hi there! This is a custom greeting.

Use a function prototype above main() and define the body of the function below main().
Call the function from main() to make sure it runs and prints the message.


Question 2

Create a function called addFive that takes an int as a parameter and returns the value plus 5.

In main():

  • Call addFive and pass in the number 10

  • Store the returned value in a variable

  • Print the result

You should see the value 15 printed when the program runs.


Question 3

Create a function called addTax that takes in a double value and returns it increased by 13 percent (multiple by 1.13).

Members only

Keep reading this lesson

You've reached the end of the free preview. Unlock the rest of this lesson plus 21 more lessons in Mastering C++.

  • Unlimited coding questions
  • Unlimited access to all classroom material
  • Weekly live call for questions and guidance
  • 3,000 AI tutor tokens / month
  • Personal SQL database (3 MB)
  • Progress tracking

Cancel any time.