Advertisement
4_2005-2006 Coding Standards #161165

How to return 2 values from a function

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

AI

สรุปโดย AI: 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.

ซอร์สโค้ด
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;
}
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine