高中數學擴充套件/數學程式設計/輸入重述
外觀
添加了一個新函式:float get_delta()。
更改了一個函式:void execute_command(char command)。
函式新增
float get_delta()
- 提示輸入 delta。
- 使用 cscanf 來保證浮點輸入。
- 呼叫 getch() 函式清空輸入緩衝區。
- 呼叫 cprintf("\n") 在輸出中向下移動一行。
- 驗證並列印 delta。
函式更改
void execute_command(char command)
- 新增程式碼以呼叫 get_delta 來處理 'd' 或 'D' 命令。
//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;
}