/* This program demonstrates * * 1. Constants and symbolic constants * 2. Using cin for input * 3. Formatting floating point output * 4. Introduction to operators */ #include #include // used for floating-point formatting using namespace std; /* A symbolic constant is a way of defining a constant that C++ inherited from C. * We use the #define directive to define a symbol (identifier) as a constant. * A symbolic constant is not a variable, since it doesn;t technically have a defined * data type and it is not stored in memory. * Intead, the preprocessor will REPLACE evey mention of the name with the value * BEFORE the program is compiled. * This is called macro expansion and creates several security vulnerabilities. * While we introduce it for enabling legacy code, they are not recommended while * writing new programs. * The following line defines a symbolic costant E of the value 2.87. */ #define E 2.87 // please note - no "=", no semicolon int main() { /* A constant is a value that does not change. * This is a variable prefixed with the keyword "const". In this case, a variable * is created and stored in memory. Also, we cannot separate the declaration and * initialization steps for const variables. It has to be done in one line. */ const double PI= 3.14159; // PI = 22/7; //error - cannot change a constant cout<> x; is equivalent to x = */ int x,y; // first 2 inputs double a; // third input cin >> x >> y >> a; /* We can now use those values in our calculations */ double sum = x + y + a; cout<<"Sum: "<