const double value : const « Language Basics « C++ Tutorial






#include <iostream>

using namespace std;

int main()
{  
   double bottles;

   cout << "How many bottles do you have? ";
   cin >> bottles;

   double cans;
   cout << "How many cans do you have? ";
   cin >> cans;

   const double BOTTLE_VOLUME = 2.0;
   const double CAN_VOLUME = 0.355;
   double total = bottles * BOTTLE_VOLUME 
      + cans * CAN_VOLUME;

   cout << "The total volume is " << total << " liter.\n";

   return 0;
}








1.8.const
1.8.1.Define constant
1.8.2.Demonstrates constants
1.8.3.const double value
1.8.4.Using a properly initialized constant variable.
1.8.5.Same Program Using Constant Integers
1.8.6.Demonstrating the const type qualifier