//******************************************************************* // // Program: Testints // // Description: Allows user to test integer operations. // // Date: 1999/10/1 - latest modification // // Course Information: CS 1711, Laboratory 2 // // Filename: testints.cpp // //******************************************************************* #include #include // this function clears the screen void clrscr(){ int i; for (i = 1; i < 24; i++) cout << endl; } /* Prints instructions for menu use. */ void DisplayHelp() { clrscr(); // this function clears the screen cout << endl; cout << "Type the number of your menu selection"; cout << endl << "and press [Enter]."; cout << "Your selection must be between 1 and 9" << endl << endl << endl ; } /* Prints the menu, prompts the user to make a selection, and then returns the number of that selection */ int GetMenuSelection() { int choice; /* Users choice. */ do { cout << endl; cout << endl << " 1. Help"; cout << endl << " 2. Set value of A."; cout << endl << " 3. Set value of B. " ; cout << endl << " 4. Set value of C." ; cout << endl << " 5. Display value of A / B"; cout << endl << " 6. Display value of A % B"; cout << endl << " 7. Display value of (A % B) % C"; cout << endl << " 8. Display value of A % (B % C)"; cout << endl << " 9. Quit"; cout << endl << endl << endl << endl << endl; cout << "Enter the number of your selection " << endl ; cin >> choice; if ((choice < 1) || (choice > 9)) { cout << ">>>>> Your selection " << choice << " is invalid. <<<<<" << endl; } } while ((choice < 1) || (choice > 9)); cout << endl ; return(choice) ; } int main() { int ExitFlag; /*: Boolean; Used to exit program. */ int A,B,C; /* Input from the user. */ clrscr(); cout << endl << "Begin TestInts ..."; A=0; B=0; C=0; ExitFlag = 0; /* Initialized to avoid exit of system. */ DisplayHelp(); do { switch(GetMenuSelection()) /* display menu/get choice*/ { case 1: DisplayHelp(); break; case 2: clrscr(); cout << endl; cout << "Enter the value of A:"<< endl ; cin >> A; clrscr(); break; case 3: clrscr(); cout << endl; cout << "Enter the value of B: "<< endl ; cin >> B; clrscr(); break; case 4: clrscr(); cout << endl ; cout <<"Enter the value of C: "<< endl ; cin >> C ; clrscr(); break; case 5: if (B == 0) { clrscr(); cout << endl << "***** Warning! *****"; cout << endl << "Because B = 0"; cout << " evaluating A / B "; cout << endl <<"will cause a run time error."<< endl << endl ; break; } cout << ">>>>> " << A <<" / " << B << " = " << (A / B) << " <<<<<"<< endl << endl ; break; case 6: if (B == 0) { cout << endl << "***** Warning! *****"; cout << endl << "Because B = 0"; cout << " evaluating A % B "; cout << endl <<"will cause a run time error." << endl << endl ; break; } cout << ">>>>> " << A <<" % " << B << " = " << (A % B); cout << " <<<<<"<< endl << endl ; break; case 7: if (C == 0) { cout << endl <<"***** Warning! *****"; cout << endl << "Because C = 0"; cout << " evaluating (A % B) % C "; cout << endl << "will cause a run time error."<< endl << endl; break; } //if c=0 if (B == 0) { cout << endl <<"***** Warning! *****"; cout << "Because B = 0"; cout << " evaluating (A % B) % C "; cout << endl << "will cause a run time error." << endl << endl; break; }//if b=0 cout << " >>>>> (" << A << " % " << B << " ) % " << C; cout << " = " << (A % B) % C << " <<<<<" << endl << endl; break; case 8: if (C == 0) { cout << "***** Warning! *****\n" ; cout << "Because C = 0"; cout << " evaluating A % (B % C) "; cout << endl << "will cause a run time error."<< endl << endl ; break; } if ((B % C) == 0) { cout << "***** Warning! *****\n" ; cout << "Because B % C = 0\n"; cout << " evaluating A % (B % C) "; cout << "will cause a run time error."<< endl << endl ; break; } cout << " >>>>> " << A << " % (" << B << " % " << C << " )" << " = " << A % (B % C) << " <<<<<" << endl << endl; break; case 9: ExitFlag = 1; } // endswitch } while (ExitFlag == 0); clrscr(); cout << endl << endl << "End TestInts." << endl; return(0); }