-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReturnPointer.cpp
77 lines (66 loc) · 1.34 KB
/
ReturnPointer.cpp
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
71
72
73
74
75
76
77
//
// Created by 不死鸟Anka on 2019-07-18.
//
#include "ReturnPointer.h"
#include <iostream>
using namespace std;
short factor(int, int*, int*);
enum ERR_CODE { SUCCESS, ERROR };
ERR_CODE factor(int, int&, int&);
int main()
{
int number, squared, cubed;
short error;
ERR_CODE result;
cout << " Enter a number ( 0 - 20 ) : ";
cin >> number;
result = factor(number, squared, cubed);
if(result == SUCCESS)
{
cout << "number: " << number << "\n";
cout << "square: " << squared << " \n ";
cout << "cubed:" << cubed << "\n";
}
else
{
cout << "Error encountered!!\n";
}
error = factor(number, &squared, &cubed);
if (!error)
{
cout << "number:" << number << "\n";
cout << "square: " << squared << " \n ";
cout << "cubed:" << cubed << "\n";
}
else
std::cout << "Error encountered!!\n";
return 0;
}
short factor(int n, int *pSquared, int *pCubed)
{
short value = 0;
if (n>20)
{
value = 1;
}
else
{
*pSquared = n * n;
*pCubed = n * n * n;
value = 0;
}
return value;
}
ERR_CODE factor(int n, int &rSquared, int &rCubed)
{
if(n > 20)
{
return ERROR;
}
else
{
rSquared = n * n;
rCubed = n * n * n;
return SUCCESS;
}
}