Programming

profileAdejoke
3.2GuidedPractice.docx

3.2 Guided PracticeUser-Defined Functions

A function is a block of code that executes certain commands when it is called.  Functions are important for reusing code and making programs more efficient.  Each program has at least one function main().  User-defined functions are functions that we create to perform tasks.  They include the following three parts:

· Prototype – declares the function telling the compiler to expect a user-defined function

· Call – calls the function definition to complete the specified commands

· Definition – stores the executable commands

  Text  Description automatically generated with low confidence

 

 

 

Things to know about functions:

· Parentheses after a named item specified that command as a function – i.e. main( ), printf( ), scanf( ), etc.

· After a function definition has been completed the program returns to the next command directly after the function call

· We can pass parameters or variable values into a function definition to be manipulated, computed, or changed.

· We can also return values back to the function call so that these values are available in the scope of another function.

· A variable is only available in the scope of its function definition

For this exercise, you will design a program that prompts the user to enter two numbers.  You need to create a function to display a message and prompt the user.  You then will add the two numbers together displaying the result to the output screen.

Instructions

Follow these instructions to complete your assignment:

1. Download the document   U3_GP_UserDefined Functions.docx Download U3_GP_UserDefined Functions.docx

2. Complete the assignment instructions.

3. Upload your .fprg, .c, and a screenshot of the C output into the Canvas dropbox for grading.

· Flowchart

· Diagram  Description automatically generated

· Code

· Graphical user interface, text, application  Description automatically generated

· Output

· Text  Description automatically generated

New Flowchart Item:  The function call shape is a rectangle with lines at both ends.  In this program, the function call is located in the main() function.

image3.png

image4.png

image1.png

image2.png