你好!!
程序改了一下,你试试吧,有问题再问:
#include <stdio.h>int main()
{
float crisps,popcorn,chocolate,cola
int i,serialnumber,frequency
crisps=3.0
popcorn=2.5
chocolate=4.0
cola=3.5
frequency=0
for(i=0i<6i++)
{
printf("请输入商品序列号serialnumber:\n")
printf(" 1、薯片(crisps)\n 2、爆米花(popcorn)\n 3、巧克力(chocolate)\n 4、可乐(cola)\n 0、退出")
printf("\nserialnumber:")
scanf("%d",&serialnumber)
if(serialnumber!=0)
{
frequency=frequency+1
if(frequency<5)
{
switch(serialnumber)
{
case 0:i=10printf("\n退出查询")break
case 1:printf("\ncrisps的价格是%f元\n\n",crisps)break
case 2:printf("\npopcorn的价格是%f元\n\n",popcorn)break
case 3:printf("\nchocolate的价格是%f元\n\n",chocolate)break
case 4:printf("\ncola的价格是%f元\n\n",cola)break
default:printf("\n选择错误\n")
}
}
else
printf("谢谢查询\n")
}
else
{
printf("谢谢查询\n")
break
}
}
}
X1,X2,X3分别检测到1、5、10元;X4汽水按钮,X5咖啡按钮,X7找零按钮;
Y1汽水灯,Y2咖啡灯,Y3汽水阀,Y4咖啡按阀,Y5找零等,Y6找零阀;
import java.util.Scannerpublic 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("你选择的是咖啡")
}
if(i==2)
{
System.out.println("你选择的是可乐")
}
if(i==3)
{
System.out.println("你选择的是茶")
}
}
public double getShopping(int i,double p)
{
if(i==1)
{
if(p<coffeeprice)
{
System.out.println("您的钱不够买此商品")
}
else
{
price=p-coffeeprice
}
}
if(i==2)
{
if(p<cokeprice)
{
System.out.println("您的钱不够买此商品")
}
else
{
price=p-cokeprice
}
}
if(i==3)
{
if(p<teaprice)
{
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(i>3||i<1)
{
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("找你的钱:"+shop.getShopping(i,p))
}
}
}
catch(Exception ex)
{
System.out.println("请正确输入!")
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)