Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我需要让我的程序重复并合计订单_C++ - Fatal编程技术网

C++ 我需要让我的程序重复并合计订单

C++ 我需要让我的程序重复并合计订单,c++,C++,我正在编写一个程序,该程序要求输入要订购的木材的类型、数量和尺寸。它应该打印数量、尺寸、类型和成本。然后,假设程序对整个订单进行合计。我有一个问题,让它重复,我不知道如何得到它的总订单 #include<string> #include<iomanip> #include<iostream> using namespace std; char chr; int main() { string order; float P; float F; float 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;
#包括
#包括
#包括
使用名称空间std;
char-chr;
int main()
{
字符串顺序;
浮动P;
浮动F;
浮点数C;
浮动M;
浮子O;
浮动T;
P=0.89;
F=1.09;
C=2.26;
M=4.50;
O=3.10;
浮动量=0;
浮动宽度=0;
浮动高度=0;
浮动长度=0;
煤焦类型;
浮动成本;
浮动b测量;
浮动总额;
b测量=(宽*高*长)/12;
字符控制;
coutquantity>>宽度>>高度>>长度;//存储信息
成本=bmeasure*数量;//计算成本
if(type='P')//如果用户订购了pine
{
b测量=(宽度*高度*长度)/12;//将给定测量值转换为板英尺的公式
cost=bmeasure*quantity;//计算成本

cout尝试查看此页面:

看看迭代部分

在这个地方搜索关于如何使用C语言的更多信息++


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

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

您知道while、do-while的循环语句吗?可能,do-while更适合此任务。请检查语法。