High School Mathematics Extensions/Mathematical Programming/Exercise 1: Implementing Commands
Appearance
Explanation
[edit | edit source]Includes
Type Definitions
Function Prototypes
Global Variables
Function Definitions
Code to change
[edit | edit source] Add and replace the following code:
//function definitions //... int get_integer() { int ret_val; char lastpress; cprintf("Enter integer: "); cscanf("%i",&ret_val); lastpress=getch(); cprintf("\n"); return ret_val; } //... void execute_command(char command) { switch (command) { case '/': output_divide(); break; case '%': output_modulus(); break; case '=': output_values(); break; case 'r': case 'R': r=get_integer(); output_values(); break; case 'l': case 'L': l=get_integer(); output_values(); break; case 'x': case 'X': done=TRUE; break; } } void output_divide() { if (r > 0) { cprintf("%d / %d = %d.\n",l,r,l/r); } else { cprintf("l = %d, r = %d. Please set r to a value other than 0.\n",r,l); } } void output_modulus() { if (r > 0) { cprintf("%d %% %d = %d.\n",l,r,l%r); } else { cprintf("l = %d, r = %d. Please set r to a value other than 0.\n",r,l); } } void output_values() { cprintf("l = %d, r = %d.\n",l,r); }