High School Mathematics Extensions/Mathematical Programming/Processing Commands

From Wikibooks, open books for an open world
< High School Mathematics Extensions‎ | Mathematical Programming
Jump to: navigation, search
High School Mathematics Extensions75% developed

Supplementary Chapters50% developedPrimes and Modular Arithmetic100% developedLogic75% developed

Mathematical Proofs75% developedSet Theory and Infinite Processes50% developed Counting and Generating Functions75% developedDiscrete Probability25% developed

Matrices100% developedFurther Modular Arithmetic50% developedMathematical Programming0% developed


Two new functions were added: char retrieve_keypress() and char validate(char check_me) and two functions were changed: void input_message(), char input().


char retrieve_keypress()

This function make sure program input and output are displayed on different lines on the console. This makes program error messages clearer, and will make the program output clearer when we print it.
  • reads a key from the console.
  • outputs a newline character to the console after it reads a key. This makes the program error message clearer, and will make the program output clearer when we print it.

char validate (char checkme)

Returns true if the character passed to it is in this set: {'=' '+' '-' 'd' 'D' 'x' 'X'} and false if it is not.


void input_message()

Changed to prompt for the commands this program will process.

char input()

Changed to
  • call retrieve_keypress to get a command
  • to validate the command
  • to print an error message and instructions if the command is not valid.

Code to change[edit]

Crystal Clear action apply.png Add and replace the following code:
 //function prototypes
 char retrieve_keypress();
 char validate(char check_me);

 //function definitions
 void input_message()
    // Prompt for Commands
    cprintf("Key      Action.\n");
    cprintf("=        Display f(x) = result.\n");       
    cprintf("d or D   Change delta.\n");
    cprintf("+        Add delta to x.\n");
    cprintf("-        Subtract delta from x.\n");
    cprintf("x or X   End program.\n");
 char input()
     // Input a character at a time
     // Validate command
     while (!validate(read))
            cprintf("\nInvalid Command.\n");
     return read;
char retrieve_keypress()
    char ret_val;
    return ret_val;
 char validate(char check_me)
    char ret_val=0;
    switch (check_me)
        case '=':
        case '+':
        case '-':
        case 'd':
        case 'D':
        case 'x':
        case 'X':   ret_val++;
    return ret_val;

Next Step[edit]