我需要让我的程序重复并完成订单

时间:2013-11-20 03:17:57

标签: c++

我正在编写一个程序,想要询问要订购的木材的类型数量和大小。打印数量,尺寸,类型和成本。然后该程序假设总计整个订单。我有一个问题让它重复,我不知道如何让它完成订单。

#include<string>
#include<iomanip>
#include<iostream>
using namespace std;
char chr;
int main()
{
string order;
float P;
float F;
float C;
float M;
float O;
float T;
P=0.89;
F=1.09;
C=2.26;
M=4.50;
O=3.10;
float quantity=0;
float width=0;
float height=0;
float length=0;
char type;
float cost;
float bmeasure;
float total;
bmeasure=(width*height*length)/12;
char cont;
cout<<"Enter item: "<<endl;  // the user enters their order    
cin>>type>>quantity>>width>>height>>length;  //stores the information 
cost=bmeasure*quantity;  //calcualtes the cost 

if(type=='P')                                              //if the user orders pine
{
  bmeasure=(width*height*length)/12;                      //equation that converts the given measurement into board feet
  cost=bmeasure*quantity;                                 //calculates the cost 
cout<<quantity<<" "<<width<<"x"<<height<<"x"<<length<<" "<<"Pine"<<", "<<"cost: "<<"$"<<fixed<<setprecision(2)<<cost*.89<<endl; //prints out the users order with the price
}
else if(type=='F')                                         //if the user orders fir
{
     bmeasure=(width*height*length)/12;
     cost=bmeasure*quantity;
    cout<<quantity<<" "<<width<<"x"<<height<<"x"<<length<<" "<<"Fir"<<", "<<"cost: "<<"$"<<fixed<<setprecision(2)<<cost*1.09<<endl;
}
else if (type=='C')
{
    bmeasure=(width*height*length)/12;
  cost=bmeasure*quantity;
     cout<<quantity<<" "<<width<<"x"<<height<<"x"<<length<<" "<<"Cedar"<<", "<<"cost: "<<"$"<<fixed<<setprecision(2)<<cost*2.26<<endl;
}
else if(type=='M')
{
  bmeasure=(width*height*length)/12;
  cost=bmeasure*quantity;
    cout<<quantity<<" "<<width<<"x"<<height<<"x"<<length<<" "<<"Maple"<<", "<<"cost: "<<"$"<<fixed<<setprecision(2)<<cost*4.50<<endl;
}
else if (type=='O')
{
    bmeasure=(width*height*length)/12;
    cost=bmeasure*quantity;
    cout<<quantity<<" "<<width<<"x"<<height<<"x"<<length<<" "<<"Oak"<<", "<<"cost: "<<"$"<<fixed<<setprecision(2)<<cost*3.10<<endl;
}
else if (type=='T')
{
    cout<<"Total Cost: "<<total<<endl;
}

cout<<"Would you like to order more? Y or N"<<endl;  //user is asked if they would like to continue
cin>>cont;
{
if(cont=='n'||cont=='N')
   cout<<"Total: "<<endl;
}
cin>>chr;



return 0;

}

2 个答案:

答案 0 :(得分:0)

尝试查看此页面:http://www.cplusplus.com/doc/tutorial/control/

查看迭代部分。

在这个视线周围搜索有关如何使用C ++的更多信息

cplusplus.com是完整的教程,可以解释这一点。

答案 1 :(得分:0)

循环中没有任何内容。尝试将所有if语句放在do-while循环中,该循环具有控制它的yes / no answer部分。