The following are C++ statements which declare different types of variables.
// make an integer variable called 'count' with initial value -3 int count = -3; // make a floating point variable called 'slope' with value 4.5 float slope = 4.5; // a char variable called 'letter' with capital A stored in it char letter = 'A'; // a boolean variable called 'flag' set to false bool flag = false;Sample program:
( 1) // Program Name: age.cpp ( 2) // Description: Tell a Person how old they are in days ( 3) // Author: Calamity Sam ( 4) // Date: September 10, 1752 ( 5) ( 6) #include <iostream> //this is needed for C++ I/O ( 7) #include <string> //this will be needed for strings ( 8) using namespace std; ( 9) (10) int main(void) { (11) //display something on a line by itself (12) cout << "Hello! How many years old are you? "; (13) int age = 0; (14) cin >> age; (15) cout << endl << "You are about " << age*365 << " days old." << endl; (16) return 0; (17) }