我的程序需要以每码 5 美元的价格计算客户更换地毯的安装成本、各种填充选项、地毯成本和总计到最近的院子。填充的成本基于:
- 好 - 每码 3 美元 - 1-3 年保修
- 更好 - 每码 4 美元 3-5 年保修
- 最佳 - 每码 5 美元 - 5-10 年保修
- 优秀 - 每码 7 美元 10-20 年保修
手术:
- 提示用户房间数量对于每个房间:
- 提示每个房间数的长度大于宽度
- 计算平方英尺a。将平方英尺转换为平方码并向上取整 b. 平方码 = 房间 c 所需的码数。按平方码计算安装成本 *$5
- 提示用户选择填充。一个。将填充成本乘以房间的平方码
- 提示用户每平方米房间的地毯成本:通过将输入乘以所需的平方码来计算成本
- 输出所需总码数
- 输出安装费用
- 输出填充成本
- 输出地毯成本
- 输出总成本 = + 安装 + PAdding + Carpet
- 总计 = 每个房间的成本
** * ** * ** * ** * ** * *** /
到目前为止,我有 5 个问题:
- 如何将整数填充选择转换为质量成本
- 地板环不会在房间之间断开
- 当它显示房间号时,它从 0 开始
- 如何让美元显示到小数点后 2 位?
我如何将每个房间的总数存储为双打以获得总计?
#include <iostream> #include <iomanip> #include <string> #include <conio.h> #include <string> using namespace std; const float INSTALL_COST = 5; const float GOOD_PAD = 3; const float BETR_PAD = 4; const float BEST_PAD = 5; const float EXC_PAD = 7; const double SQU_FT_YD = 9; int main () { int padding, rooms, numreq, squareYards; double length, width, squareFeet,priceSquareYard; double paddingCost, installFee, totalCost, carpetCost; //step 1: cout << "Enter number of rooms: "; cin >> numreq; cout << endl; //Step 2 cout << "Enter length of room: "; cin >> length; cout << endl; cout << "Enter width of room: "; cin >> width; cout << endl; //step 3 cout << "Select quality of padding:<1-4> "; cout << "\n1. Good - $3 per yard - 1-3 year warranty \n2. Better - $4 per yard 3-5 year warranty \n3. Best- $5 per yard - 5-10 year warranty \n4. Excellent - $7 per yard 10-20 year warranty: "; cin >> padding; cout << "Enter price of carpeting per square yard of room: "; cin >> priceSquareYard; //step3 for(int x = 0; x < numreq; x++) { squareFeet = length * width; squareYards = ((squareFeet / SQU_FT_YD) + 0.5); if (squareYards > 0) squareYards++; installFee = squareYards * INSTALL_COST; carpetCost = priceSquareYard * squareYards; paddingCost = squareYards * padding; totalCost = carpetCost + installFee + paddingCost; cout << "\n Room " << x << " Yards Required = " << squareYards; cout << "\n Room " << x << " Installation = $" <<installFee; cout << "\n Room " << x << " Padding Cost = $" << paddingCost; cout << "\n Room " << x << " Carpet Cost = $" << carpetCost; cout << "\n Room " << x << " Total Cost = $" << totalCost; } _getch(); return 0;
}