⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 soln2_4.cpp

📁 Wrox.Ivor.Hortons.Beginning.Visual.C.Plus.Plus.2008 With sourcecode
💻 CPP
字号:
// Soln2_4.cpp
#include <iostream>
using std::cout;
using std::endl;

/* As specified the program calculates the aspect ration by dividing one integer value by another.
   The result of this is always an integer  so it is a very poor measure of the aspect ratio
   in general.
   A much better way is to carry out the calculation using floating-point arithmetic. To do this
   you just need to cast either of the operands for the division to a floating-point type, as shown below.
   The compiler will arrange for the other operand to be converted to the same type.
*/

int main()
{
   int width = 1280;
   int height = 1024;
//   double aspect = width / height;
   double aspect = static_cast<double>(width) / height;

   cout << "The aspect ratio is " 
        << aspect;
   cout << endl;

   return 0;
}

⌨️ 快捷键说明

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