-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariabel.cpp
More file actions
40 lines (34 loc) · 1.62 KB
/
Copy pathvariabel.cpp
File metadata and controls
40 lines (34 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string> // Recommended for using string variables
using namespace std;
int main() {
// ==========================================
// 1. DATA TYPES & VARIABLE DECLARATION
// ==========================================
int myNum = 5; // Integer (whole numbers without decimals)
double myFloatNum = 5.99; // Floating point number (numbers with decimals)
char myLetter = 'D'; // Character (single character in single quotes)
string myText = "Hello"; // String (text wrapped in double quotes)
bool myBoolean = true; // Boolean (true/1 or false/0)
// ==========================================
// 2. PRINTING VARIABLES IN OUTPUT
// ==========================================
int myAge = 35;
cout << "=== PRINTING VARIABLES ===" << endl;
cout << "I am " << myAge << " years old." << endl;
// Combining multiple variables in a single output statement
string name = "John";
int age = 35;
double height = 6.1;
cout << name << " is " << age << " years old and " << height << " feet tall." << endl;
// ==========================================
// 3. CONSTANTS (Unchangeable Variables)
// ==========================================
// The 'const' keyword creates read-only variables.
// Trying to assign a new value to a const variable will cause a compile error.
const int minutesPerHour = 60; // Value is locked to 60
const double PI = 3.14159; // Useful for values that should never change
cout << "\n=== CONSTANTS ===" << endl;
cout << "Minutes per hour: " << minutesPerHour << endl;
return 0;
}