Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

High School Mathematics Extensions/Mathematical Programming/Exercise 1: Implementing Commands

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Explanation Includes Type Definitions Function Prototypes Global Variables Function Definitions Code to change 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); } Next Step ../Exercise 1: The Complete Program/