#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.9\n" << "4梨 2.50,5柚子 3.70,6猕猴桃 7.60,7山楂 3.90" << endl;
int num_choice = 0;
while (1)
{
int Y_N;
cout << "请输入你你要购买的种类数量:";
cin >> num_choice;
if (num_choice == 0)
{
cout << "您确定只是看看吗?要不买点吧?继续请按1,退出请按0" << endl;
cin >> Y_N;
if (Y_N == 0)
{
cout << "退出成功!" << endl;
break;
}
else if (Y_N == 1)
{
}
else
cout << "不要捣乱,请按规定输入哦,亲" << endl;
}
else
{
cout << "种类编号分别为:";
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;
}
以上是程序,请无视掉小白的system("pause")
以下是错误提示
error C2065: “choice”: 未声明的标识符
error C2541: “delete”: 不能删除不是指针的对象
error C2065: “choice”: 未声明的标识符
error C2065: “quantity_choice”: 未声明的标识符
error C2541: “delete”: 不能删除不是指针的对象
error C2065: “quantity_choice”: 未声明的标识符
应该是因为自己不熟悉int *XXXXX=new int[XXX]的用法,哪位大咖来给讲一下,谢谢了。