Advertisement
7_2009-2012 Coding Standards #228719

How to return 2 values from a function

Will return 2 values from a function by passing 2 variables by reference.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
#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;
}
Original Comments (3)
Recovered from Wayback Machine