-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompound_assignment_operators.cpp
47 lines (35 loc) · 1.46 KB
/
compound_assignment_operators.cpp
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
41
42
43
44
45
46
47
//This program demonstrates the concept of Compund Assignment operators in C++.
// Include the iostream library to allow for input/output operations
#include <iostream>
// Use the standard namespace to avoid having to type std:: before common operations like cout
using namespace std;
// The main function, where the program starts
int main()
{
// Declare and initialize two float variables, a and b
float a = 10;
float b = 13;
// Print a title for the program
cout <<"*** Compound Assignment Operators ***" << endl;
// Declare and initialize a float variable named value
float value = 5;
cout <<"The values are: Variable = " << value << ", a = "<< a << ", b = "<< b << endl;
// Add the value of a to value and store the result in value
value += a;
// Print the new value after the addition
cout <<"After Variable += a : "<< value << endl;
// Subtract the value of b from value and store the result in value
value -= b;
// Print the new value after the subtraction
cout <<"After Variable -= b: "<< value << endl;
// Multiply the value by a and store the result in value
value *= a;
// Print the new value after the multiplication
cout <<"After Variable *= a: "<< value << endl;
// Divide the value by b and store the result in value
value /= b;
// Print the new value after the division
cout <<"After Variable /= b: "<< value << endl;
// End of the main function
return 0;
}