-5
#include<iostream>

using namespace std;
int main()

int quantity = 0;
int a = 0;
int b = 0;
int x = 0;
int y = 0;
int z;
double region[5][6];
int shipping = 20.00;
region[0][0] = 0;


for (x=0;x<5;x++) {

    for (y=0; y<6; y++) {
        z=x;
       if(y == 0)
       {region[x][y] = y + 1 + z;}
       else if(y == 1)
       {region[x][y] =  region[x][y-1] * 2;}
           else if(y == 2)
           {region[x][y] = region[x][y-1]  + .50;}
               else if(y == 3)
                   {region[x][y] = region[x][y-1] + .50;}
                   else if(y == 4)
                   {region[x][y] = region[x][y-1] + .250;}
                       else 
                       {region[x][y] = region[x][y-1] + .250;}
    }

}
cout<<"Please input the region"<<endl;
cin>>a;
cout<<"Enter quantity"<<endl;
cin>>quantity;
if (quantity > 6)
{b = 5;}
else
{b = quantity;}

cout<<"The price of shipping comes out to: "<<region[a][b] + shipping<<" Since $20 is added for the shipping cost"<<endl;

return 0 ;

}

所以现在我必须为区域和数量输入 0,0 才能获得第一个单元格。但由于我从区域 1 和数量 1 开始,所以我要让用户输入 1,1。我将如何使用 C++ 进行此操作。谢谢!

4

2 回答 2

1

用户进入区域后,验证所有值是否大于 0。如果从它们中减去 1,并像现在一样处理数据。

if(a < 1) a = 1;
if(quantity < 1) quantity = 1;

// Subtract 1 from the values
a--;
quantity--;

if (quantity > 6)
{b = 5;}
else
{b = quantity;}
cout<<"The price of shipping comes out to: "<<region[a][b] + shipping<<" Since $20 is added for the shipping cost"<<endl;
于 2013-05-22T00:59:30.630 回答
0

每个值减 1 怎么样?

cout<<"Please input the region"<<endl;
cin>>a;
cout<<"Enter quantity"<<endl;
cin>>quantity;

--a;
--quantity;
于 2013-05-22T01:00:36.360 回答