首先先是改进收银的程序,引入常量,示例一:
#include <stdio.h>
int main()
{
const int AMOUNT = 100;
int price = 0;
printf("请输入金额(元):");
scanf("%d",&price);
int change = AMOUNT - price;
printf("找您%d元。\n",change) ;
return 0 ;
}
其中的const为常量的意思,通过const后,AMOUNT为常量且不会被改变。
其次是示例二,一个简单的计算过程: