ex2_05.cpp

来自「Visual C++ 2005的源代码」· C++ 代码 · 共 40 行

CPP
40
字号
// Ex2_05.cpp
// Calculating how many rolls of wallpaper are required for a room
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
   double height = 0.0, width = 0.0, length = 0.0; // Room dimensions
   double perimeter = 0.0;                         // Room perimeter

   const double rollwidth = 21.0;                  // Standard roll width
   const double rolllength = 12.0*33.0;            // Standard roll length(33ft.)

   int strips_per_roll = 0;                        // Number of strips in a roll
   int strips_reqd = 0;                            // Number of strips needed
   int nrolls = 0;                                 // Total number of rolls

   cout << endl                                    // Start a new line
        << "Enter the height of the room in inches: ";
   cin >> height;

   cout  << endl                                   // Start a new line
         << "Now enter the length and width in inches: ";
   cin >> length >> width;

   strips_per_roll = rolllength / height;          // Get number of strips per roll
   perimeter = 2.0*(length + width);               // Calculate room perimeter
   strips_reqd = perimeter / rollwidth;            // Get total strips required
   nrolls = strips_reqd / strips_per_roll;         // Calculate number of rolls

   cout << endl
        << "For your room you need " << nrolls << " rolls of wallpaper."
        << endl;

   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?