-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserDefinedFunctionsDEMO.cpp
More file actions
70 lines (48 loc) · 1.38 KB
/
Copy pathUserDefinedFunctionsDEMO.cpp
File metadata and controls
70 lines (48 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//************************************************************************
// Author: Rolando Carreon
// Date: mar 4 2025
// Language: C++
// Assignment: userdefinedfunctionsDEMO
// Description: adds two integrers
//************************************************************************
#include<iostream>
using namespace std;
// function prototypes
int add(int, int);
void printGreeting();
void printDifference(int, int);
int main()
{
// declare local variables
int num1 = 5, num2 = 10;
int sum;
// display the user greeting
printGreeting();
// call the function to get the sum of the numbers
sum = add(num1, num2);
//display the result
cout << "The sum is " << sum << endl;
// get the difference in the numbers
printDifference(num1, num2);
return 0;
}
// function definitions
// function accepts two integers and reyrns the sum
int add(int firstNum, int secondNum)
{
return firstNum + secondNum;
}
// function to display a greeting to the user
void printGreeting()
{
cout << "Hello, World!\n";
}
// function that accepts two integrers and displays the difference
// the difference is firstNum - secondNum
void printDifference(int firstNum, int secondNum)
{
// declare local variables
int diff = firstNum - secondNum;
// display the result
cout << "The difference is: " << diff << endl;
}