我一生都无法弄清楚我在腻子中的这些简单方程式有什么问题。我认为一切都设置正确,但我的输出与我的教授样本输出略有不同。
//This program is used to calculate total cost of painting.
#include <iostream>
#include <iomanip>
using namespace std;
//These are the function prototypes that will be used for the main function.
void displayInstructions(int &feet, float &price);
float paintprice (int feet, float price);
float laborprice (int feet);
float totalcost(float paint, float labor);
void displayoutput (float paint, float labor, float total, int feet);
int main()
{
int feet=0;
float price=0;
float paint=0;
float labor=0;
float total=0;
displayInstructions(feet, paint);
paint=paintprice(feet, paint);
labor=laborprice(feet);
total=totalcost(labor, paint);
displayoutput(paint, labor, total, feet);
return 0;
}
void displayInstructions(int &feet, float &price)
{
cout<<setw(35)<<"==================================="<<endl;
cout<<setw(30)<<"Painting Cost Calculator" <<endl;
cout<<setw(35)<<"===================================" <<endl;
cout<<"This program will compute the costs (paint, labor, total)\nbased on th\
e square feet of wall space to be painted \
and \nthe price of paint." <<endl;
cout<<"How much wall space, in square feet, is going to be painted?" <<endl;
cin>>feet;
cout<<"How much is the price of a gallon of paint?" <<endl;
cin>>price;
}
float paintprice (int feet, float price)
{
float paint;
paint=((feet/115)*price);
return paint;
}
float laborprice (int feet)
{
float labor;
labor=((feet/115)*18*8);
return labor;
}
float totalcost (float paint, float labor)
{
float total;
total=(paint+labor);
return total;
}
void displayoutput (float paint, float labor, float total, int feet)
{
cout<<"Square feet:" <<feet <<endl;
cout<<"Paint cost:" <<paint <<endl;
cout<<"Labor cost:" <<labor <<endl;
cout<<"Total cost:" <<total <<endl;
}
基于输入为英尺=12900,价格=12.00 油漆成本的最终输出应为 1346.09 美元 人工成本的最终输出应为 16153.04 美元
我分别得到:$1344.00、$16128.00
如果你能帮助我,这将是一个救生员。