File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55#include < iostream>
66using namespace std ;
77
8- void increment (int * a, int * b);
8+ // function prototype
9+ void result (int * paramOne, int * paramTwo);
910
1011int 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 (¶mOne, ¶mTwo);
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}
You can’t perform that action at this time.
0 commit comments