给个很简单的代码

来源:百度知道 编辑:UC知道 时间:2024/05/09 07:46:24
商店批发衣服,一次性5件一下的不打折,5-10件 打8.5折 10以上打7折 已经 衣服单价为 100元/件 编写一个 可以直接看每件多少钱的 代码

main()
{int i,j;
printf("你要买多少件?");
scanf("%d",&i);
if(i<=0)printf("error");
else if(i>10)j=70;
else if(i>=5)j=85;
else j=100;
printf("单价是%d元/件",j);
}

写个C++的.
/////////////////////////////////////////////////////

//filetype console
//filename price.cpp

#include <iostream>

using namespace std;

int main()
{
cout<<"欢迎使用本系统"<< endl;

int num=0;

while(num!=-1) {

cout<< "请输入衣服的件数(enter -1 and Quit):"<<endl;
cin>> num;

if((num!=-1)&&(num<=0))
cout<<"非法的输入,件数必须为正整数";

else if(num>0&&num<5)
cout<< "每件衣服100元";

else if(num>=5&&num<=10)
cout<<"每件衣服85元";

else if(num>10)