/*这个程序,参数之间只能有一个空格,如果要支持多个空格再和我说吧*/
#include
#include
#include
#define MONEYMAX 500 //投钱最大次数,即金额参数最大500个
#define GOODSMAX 500 //选物品最大次数,即商品参数最大500个
typedef struct
{
int iGoodsSeq; //商品编号
char cGoodsName[20]; //商品名称
int iGoodsValue; //商品价格
int iGoodsBuy; //商品购买数量
}T_Goods;
T_Goods tGoods[10]=
{
{ 1, "Water", 1, 0},
{ 2, "Milk", 1, 0},
{ 3, "Beer", 3, 0},
{ 4, "water", 3, 0},
{ 5, "Oolong-Tea", 1, 0},
{ 6, "Green-Tea", 2, 0},
{ 7, "Bread", 1, 0},
{ 8, "Drinks", 2, 0},
{ 9, "Sugar", 1, 0},
{ 10, "Jelly", 1, 0},
};
void main()
{
int iResult=0;
int i=0;
int j=0;
char cMoney[MONEYMAX*3];
char cGoods[GOODSMAX*3];
int iMoney[MONEYMAX];
int iGoods[GOODSMAX];
int sumMoney=0;
int sumGoods=0;
//初始化
memset( cMoney, 0, sizeof(cMoney));
memset( cGoods, 0, sizeof(cGoods));
for (i=0; i sumMoney)
{
printf("money is low
");
return;
}
//输出购买金额情况
printf("Total: %d yuan, change: %d yuan
", sumMoney, sumMoney - sumGoods);
//输出购买商品情况
for (i=0; i 10)
{
printf("last goods %d input error [1,2,5,10]
", piGoods[i]);
return -1;
}
break;
}
else
{
//获取每一个商品
FLen = FindE - FindS;
memset( sTemp, 0, sizeof(sTemp));
memcpy( sTemp, FindS, FLen);
piGoods[i] = atoi(sTemp);
if (piGoods[i] 10)
{
printf("last goods %d input error [1,2,5,10]
", piGoods[i]);
return -1;
}
FindS = FindE 1;
FLen = 0;
}
}
}
return 0;
}。
全部