/* ************************************************************************** * Program name : 051_Arrays_of_pointer (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/07/01 - first version * ************************************************************************** * Description : (a) Input an integer number (0-5) * * (b) Output an error message * * (c) Output the memory address and elements of Values * * (d) Try again ? * ************************************************************************** */ #include #include void Displaymessage(int); int main() { // part 1 : declaration int Number; char Again; do { // part 2 : Input an integer number (0-5) do { cout << "\n\nPlease input an integer number (0 - 5) : "; cin >> Number; } while (Number<0 || Number>5); // part 3 : Output the message Displaymessage(Number); // Note (1) // part 4 : try another number ? cout << "\n\n\tTry another number (Y/N) : "; cin >> Again; cout << "\n"; } while (Again=='Y' || Again=='y'); cout << "\n" << endl; system("PAUSE"); return 0; } void Displaymessage(int Number) { static char *err[] = {"File not found","No record","Can not open file", "Write-protect error","Disk Full","System halt"}; cout << "\n\tError code (" << Number << ") : " << err[Number] << "\n\n"; int Index; // Note (2) cout << "\n\t----------------------------------------------------" << "\n\tMemory Location" << "\tNo." << "\tMessage" << "\n\t----------------------------------------------------"; for (Index=0; Index<=5; Index++) cout << "\n\t" << &err[Index] << "\t" << Index << "\t" << err[Index]; cout << "\n\t----------------------------------------------------"; } /* Notes (1) The function returns or output a message given its code number. Example : Please input an integer number (0 - 5) : 3 Error code (3) : Write-protect error (2) Show all the messages and their memory locations Example : ---------------------------------------------------- Memory Location No. Message ---------------------------------------------------- 0x414008 0 File not found 0x41400c 1 No record 0x414010 2 Can not open file 0x414014 3 Write-protect error 0x414018 4 Disk Full 0x41401c 5 System halt ---------------------------------------------------- */