High School Mathematics Extensions/Mathematical Programming/Input Revisited

Explanation

edit

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
  The following code is valid:
 //function prototypes
 //...
 float get_delta();

 //function definitions
 //...
 void execute_command(char command)
 {
 //...
        case 'D':   delta=get_delta();
                    break;
 //...
 float get_delta()
 {
    float f_val;
    char lastpress;
    cprintf("Enter delta: ");
    cscanf("%f",&f_val);
    lastpress=getch();
    cprintf("\n");
    if(f_val < 0.001)
       {
           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);
       }
    else
       {
            cprintf("Delta set to %f.\n",f_val);
       }
    return f_val;
 }


Next Step

edit