#include
using namespace std;
double capital = 0.0;
double cal(int num, double quantity)
{
switch (num)
{
case 0:
return quantity*1.50;
case 1:
return quantity*1.70;
case 2:
return quantity*4.60;
case 3:
return quantity*0.90;
case 4:
return quantity*2.50;
case 5:
return quantity*3.70;
case 6:
return quantity*7.60;
case 7:
return quantity*3.90;
}
}
int main()
{
cout << "提示:本店提供8种水果,如下(左边为水果编号及名称,右边为价格)" << endl;
cout << "0西瓜 1.50,1木瓜 1.70,2哈密瓜 4.60,3苹果 0.90\n"
<<"4梨 2.50,5柚子 3.70,6猕猴桃 7.60,7山楂 3.90 "<< endl;
int num_choice = 0;
while (1)
{
int Y_N;
cout << "您确定只是看看吗?要不买点吧?继续请按1,否则请按0,直接退出" << endl;
cin >> num_choice;
if (num_choice == 0)
{
cout << "退出成功!" << endl;
cin >> Y_N;
if (Y_N = 0)
{
cout << "不要捣乱,按规则输入,亲" << endl;
break;
}
else if (Y_N = 1)
{
}
else
cout << "种类编号为:" << endl;
}
else
{
cout << "请输入对应购买种类的重量:" << endl;
int *choice = new int[num_choice];
double *quantity_choice = new double[num_choice];
for (int i = 0; i < num_choice; i++)
cin >> choice[i];
cout << "请输入对应购买种类的重量:";
for (int i = 0; i < num_choice; i++)
cin >> quantity_choice[i];
for (int j = 0; j < num_choice; j++)
{
capital += cal(choice[j], quantity_choice[j]);
}
cout << "继续购物吗?继续请按1,否则请按0,开始结算" << endl;
cin >> Y_N;
if (Y_N = 0)
{
cout << "开始结算,请付" << capital << "元" << endl;
break;
}
else if (Y_N = 1)
{
}
else
cout << "不要捣乱,按规则输入,亲" << endl;
}
}
delete[] choice;
choice=NULL;
delete[] quantity_choice;
quantity_choice = NULL;
system("pause");
return 0;
}
“delete[] choice;”中的“choice”和“ delete[] quantity_choice;”中的“quantity_choice”均显示未定义标识符