2013-05-22 120 views
-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 ; 

}从1开始代码而不是0?

所以现在我必须键入0,0区域和数量,以获得第一个单元格。但是,因为我从区域1和数量1开始,所以我要让用户输入1,1。我将如何去用C++来做这件事。谢谢!

回答

1

用户输入区域后,验证所有值都大于0.如果他们从中减去一个,并像现在一样处理数据。

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; 
+0

谢谢你的工作完美 –

0

那么对每个值减1呢?

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

--a; 
--quantity; 
相关问题