larrywong146 2017-06-21 03:05 采纳率: 0%
浏览 745

新人求助~内存释放问题

#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”均显示未定义标识符图片说明

  • 写回答

2条回答 默认 最新

  • SuperKilling 2017-06-21 05:20
    关注

    please try
    delete choice;
    delete quantity_choice;

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型