贩卖机代码java 贩卖机bug( 三 )


strcpy(amaNEW-spName,VSPname);
amaNEW-spNum=VSPnum;
amaNEW-spValue=https://www.04ip.com/post/VSPvalue;
amaNEW-next=NULL;
if(AMAhead-next==NULL)//首次新增该节点为首节点头结点链表指针和尾节点指针均指向该节点首地址
{
amaP1=amaNEW;
AMAhead-next=amaP1;
*AMAtail=amaP1;
}
else//添加到链表
{
(*AMAtail)-next=amaNEW;
*AMAtail=amaNEW;
}
printf("\n商品%s,数量%d个,价格%.1f元 已添加到贩卖机中\n",VSPname,VSPnum,VSPvalue);
}
}
float * buySP(AMA *AMAhead,char *name,int num,float pay)//购买返回float数组[2]
//购买商品成功返回[0]=1 [1]=找还金额
//失败库存不足返回[0]=2 [1]=当前库存
//失败金额不足返回[0]=3 [1]=还需支付金额
//失败货物不存在(一般不可能出现) [0]=4 [1]=4
{
float *err=(float *)malloc(sizeof(float)*2);
amaSelect=selectSP(AMAhead,name);
if(amaSelect!=NULL)//商品已存在 核实数量和价格
{
if((amaSelect-spNum)num)
{
err[0]=2;
err[1]=(float)(amaSelect-spNum);
}
if((amaSelect-spNum)=numnum*(amaSelect-spValue)pay)
{
err[0]=3;
err[1]=num*(amaSelect-spValue)-pay;
}
if((amaSelect-spNum)=numnum*(amaSelect-spValue)=pay)
{
err[0]=1;
err[1]=pay-num*(amaSelect-spValue);
amaSelect-spNum=amaSelect-spNum-num;
}
}
else
{
err[0]=4;
err[1]=4;
}
return err;
}
跪谢!求用JAVA编写一个自动贩卖机的程序import java.util.Scanner;
public class Shop
{
private String coffee="咖啡";
private String coke="可乐";
private String tea="茶";
private double coffeeprice=2.00;
private double cokeprice=3.00;
private double teaprice=5;
private double price=0.0;
public Shop()
{
}
public void getName(int i)
{
if(i==1)
{
System.out.println("你选择贩卖机代码java的是咖啡");
}
if(i==2)
{
System.out.println("你选择贩卖机代码java的是可乐");
}
if(i==3)
{
System.out.println("你选择的是茶");
}
}
public double getShopping(int i,double p)
{
if(i==1)
{
if(pcoffeeprice)
{
System.out.println("您的钱不够买此商品");
}
else
{
price=p-coffeeprice;
}
}
if(i==2)
{
if(pcokeprice)
{
System.out.println("您的钱不够买此商品");
}
else
{
price=p-cokeprice;
}
}
if(i==3)
{
if(pteaprice)
{
System.out.println("您的钱不够买此商品");
}
else
{
price=p-teaprice;
}
}
return price;
}
public static void main(String[] args)
{
Shop shop=new Shop();
try
{
System.out.println("请选择你想要的商品\n 1.咖啡 2.可乐 3.茶");
Scanner si=new Scanner(System.in);
int i=si.nextInt();
System.out.println(" ");
if(i3||i1)
{
System.out.println("没有此产品");
}
else
{
shop.getName(i);
System.out.println(" ");
System.out.print("请付账:");
Scanner sp=new Scanner(System.in);
double p=sp.nextDouble();
System.out.println(" ");
if(shop.getShopping(i,p)!=0.0)
{
System.out.println("找你的钱贩卖机代码java:"+shop.getShopping(i,p));
}
}
}
catch(Exception ex)
{
System.out.println("请正确输入!");
}
}
}
求一个自动贩卖机的C++源代码程序#include iostream
#include string
#include vector
#include cstdlib
using namespace std;

推荐阅读