I'm a little confused.
in this program ive writted from a book it says
it sets a variable Value and says, if number > 20, set Value = 1 else Value = 0 right. if its 1, display an error message otherwise continue with program.
is Value a default variable built for this specific task?
Code:
#include <iostream>
using namespace std;
typedef unsigned short int USHORT;
short Factor(USHORT, USHORT*, USHORT*);
int main()
{
USHORT Number, Squared, Cubed;
short Error;
cout <<"Enter number (0-20): ";
cin >> Number;
Error = Factor(Number, &Squared, &Cubed);
if(!Error)
{
cout <<"Number: " << Number << "\n";
cout <<"Square: " << Squared << "\n";
cout <<"Cube: " << Cubed << "\n";
}
else
cout <<"Error Encountered!!!\n";
system("PAUSE");
return 0;
}
short Factor(USHORT n, USHORT *pSquared, USHORT *pCubed)
{
short Value = 0;
if(n > 20)
Value = 1;
else
{
*pSquared = n*n;
*pCubed = n*n*n;
Value = 0;
}
return Value;
}
i am just wondering. if it isnt built for this, can someone just explain how value is making the decision to display error or not because its not in the main function of the program and it isnt set to any other variable or whatever. im a little confused.
Im just confused as to how Value knows to display ERROR