High School Mathematics Extensions/Mathematical Programming/Input Revisited

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


One new functions was added: float get_delta().

One function was changed: void execute_command(char command).

Function Additions

float get_delta()

  • Prompts for delta.
  • Uses cscanf to guarantee floating point input.
  • Calls getch() function to empty input buffer.
  • Calls cprintf("\n") to move down a line in output.
  • Validates and prints delta.

Function Changes

void execute_command(char command)

  • Add code to call get_delta for 'd' or 'D' commands.

Code to copy[edit]

Crystal Clear action apply.png The following code is valid:
 //function prototypes
 float get_delta();

 //function definitions
 void execute_command(char command)
        case 'D':   delta=get_delta();
 float get_delta()
    float f_val;
    char lastpress;
    cprintf("Enter delta: ");
    if(f_val < 0.001)
           cprintf("Delta must be floating point number greater than or equalt to 0.001.\nDelta set to %f.\n",f_val);
            cprintf("Delta set to %f.\n",f_val);
    return f_val;

Next Step[edit]