Created
May 9, 2017 12:28
-
-
Save titus-shoats/d9abe8752f6239e76ed6de1fe84f7540 to your computer and use it in GitHub Desktop.
Returning multiple values by reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
using namespace std; | |
void FreezeWindow(); | |
void FreezeWindow() { | |
char response; | |
cin >> response; | |
} | |
enum ERR_CODE{SUCCESS, ERROR}; | |
ERR_CODE Factor(int n, int &pSquared, int &pCubed); | |
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 << endl; | |
cout << "square: " << squared << endl; | |
cout << "cubed: " << cubed << endl; | |
} | |
else { | |
cout << "Error encountered" << endl; | |
} | |
FreezeWindow(); | |
return 0; | |
} | |
ERR_CODE Factor(int n, int &rSquared, int &rCubed) { | |
// set value to 1, dont change square or cube values | |
if (n > 20) { | |
return ERROR; | |
} | |
else { | |
// if n is 3 | |
// Change square, and cube values, set value to 0 | |
rSquared = n*n; // 9 | |
rCubed = n*n*n; // 27 | |
return SUCCESS; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment