home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Using Visual C++ 4 (Special Edition)
/
Using_Visual_C_4_Special_Edition_QUE_1996.iso
/
ch13
/
badgoto.cpp
next >
Wrap
C/C++ Source or Header
|
1995-09-18
|
560b
|
25 lines
// Get needed include files
#include <limits.h>
#include <iostream.h>
unsigned short Add(unsigned short addend1, unsigned short addend2)
{
unsigned long sum = addend1 + addend2;
if (sum > USHRT_MAX)
goto OverflowError; // Illegal _ can't leave Add()
return (unsigned short) sum;
}
void main()
{
unsigned short Result = Add(12345, 54321);
cout << "The answer is " << Result << "\n";
return;
// Error handling section - but you'll never get here using
// this program
OverflowError:
cout << "Overflow error!\n";
return;
}