Skip to content

Commit ce7c31f

Browse files
Update main.cpp
1 parent d178125 commit ce7c31f

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

Pointers/main.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,40 @@
55
#include <iostream>
66
using namespace std;
77

8-
void increment(int* a, int* b);
8+
//function prototype
9+
void result(int* paramOne, int* paramTwo);
910

1011
int main() {
11-
12-
int a, b;
12+
//local variables
13+
int paramOne, paramTwo;
1314

1415
cout<<"--------------------------------------------------------------------------"<<endl;
1516
cout<<"This program will output the sum of two numbers and their absolute value"<<endl;
1617
cout<<"--------------------------------------------------------------------------"<<endl;
1718
cout<<"Enter the first number: "<<endl;
18-
cin>>a;
19+
cin>>ParamOne;
1920
cout<<"Enter the second number: "<<endl;
20-
cin>>b;
21+
cin>>paramTwo;
2122

22-
increment(&a, &b);
23+
//sending user input to increment function
24+
result(&paramOne, &paramTwo);
2325

2426
return 0;
2527
}
2628

27-
void increment(int* a, int* b){
29+
void result(int* paramOne, int* paramTwo){
2830
int sum = 0;
29-
int absoluteV = 0;
30-
31-
sum = *a + *b;
32-
absoluteV = *a + *b > 0 ? *a - *b : -(*a - *b);
31+
int absoluteValue = 0;
32+
//calculating the sum of two numbers
33+
sum = *paramOne + *paramTwo;
34+
//calculating the absolute value of two numbers by using ternary operator
35+
absoluteValue = *paramOne + *paramTwo > 0 ? *paramOne - *paramTwo : -(*paramOne - *paramTwo);
3336

34-
*a = sum;
35-
*b = absoluteV;
37+
*paramOne = sum;
38+
*paramTwo = absoluteValue;
3639

40+
//printing results
3741
cout<<"The sum of the two numbers are "<<sum<<endl;
38-
cout<<"The absolute value of the two numbers are "<<absoluteV<<endl;
42+
cout<<"The absolute value of the two numbers are "<<absoluteValue<<endl;
3943

4044
}

0 commit comments

Comments
 (0)