VB icon

How to return 2 values from a function

Email
Submitted on: 1/4/2015 2:20:00 PM
By: Josh Nixon (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: C++ (general)
Views: 1295
 
     Will return 2 values from a function by passing 2 variables by reference.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :How to return 2 values from a function
//**************************************
#include <iostream.h>
#include <conio.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: How to return 2 values from a function
// Description:Will return 2 values from a function by passing 2 variables by reference.
// By: Josh Nixon (from psc cd)
//
// Assumes:Will return 2 values from a function by passing 2 variables by reference.
//**************************************

#include <iostream.h>
#include <conio.h>
short Math_Stuff(int, int*, int*);
int main()
{
 int Num = 0, MCube = 0, MSquared = 0;
 short Error;
clrscr();
cout<<"Enter in number to square and cube: ";
cin>>Num;
 Error = Math_Stuff(Num, &MCube, &MSquared);
 if(!Error)
{
	cout<<"The number is: "<<Num;
	cout<<endl<<"The cube of "<<Num<<": "<<MCube;
	cout<<endl<<"The square of "<<Num<<": "<<MSquared;
	getch();
}
 else
cout<<"An error has occured";
return 0;
}
short Math_Stuff(int N, int *Cube, int *Sqaured)
{
 short Value = 0;
if(N > 20)
Value = 1;
else
*Sqaured = (N*N);
*Cube = (N*N*N);
Value = 0;
return Value;
}


Other 17 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.