其他分享
首页 > 其他分享> > 查询自动售货机商品的价格

查询自动售货机商品的价格

作者:互联网

#include<iostream>
using namespace std;
int main()
{
	int choice,i;
	double price;
	cout<<"[1] crisps"<<endl;
    cout<<"[2] popcorn"<<endl;
    cout<<"[3] chocolate"<<endl;
    cout<<"[4] cola"<<endl;
    cout<<"[0] exit"<<endl;
    for(i=1;i<=5;i++)        //循环语句的开始
    {
    cin>>choice;
    if (choice == 0)break;
    else 
        switch (choice){
    	case 1:price = 3.0;break;
    	case 2:price = 2.5;break;
    	case 3:price = 4.0;break;
    	case 4:price = 3.5;break;
    	default:price = 0.0;break;
	    }
	    printf("price = %.1lf\n",price);
	} 
	cout<<"Thanks";
	
	return 0;
}

标签:case,cout,int,price,查询,break,商品,自动售货机,choice
来源: https://blog.csdn.net/courage_sir/article/details/119462412