O'Reilly logo

SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using int Variables and Constants

A variable allows the program to perform its calculation outside of the cout statement.

  1: #include <iostream>
  2:
  3: using namespace std;
  4:
  5: int main(int argc, char* argv[])
  6: {
 *7:    const int Dividend = 6;
 *8:    const int Divisor = 2;
 *9:
*10:   int Result = (Dividend/Divisor);
*11:   Result = Result + 3;// Result is now its old value+3=6
*12:
*13:   cout << Result << endl;
 14:
 15:    // Note: You must type something before the Enter key
 16:    char StopCharacter;
 17:    cout << endl << "Press a key and \"Enter\": ";
 18:    cin >> StopCharacter;
 19:
 20:    return 0;
 21: }

Lines 7–13 have been changed.

Lines 7 and 8 declare variables ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required