-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconst.cpp
More file actions
23 lines (17 loc) · 722 Bytes
/
const.cpp
File metadata and controls
23 lines (17 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
void printCircumferenceAndArea(const double &PI, const double radius);
int main() {
// const is a keyword that is used to declare a constant variable
// tells the compiler to prevent anything form modifying it. (read-only)
const double PI = 3.14;
double radius = 5.0;
// pi = 100; // this will cause an error because pi is a constant
printCircumferenceAndArea(PI, radius);
return 0;
}
void printCircumferenceAndArea(const double &PI, const double radius) {
double circumference = 2 * PI * radius;
double area = PI * radius * radius;
std::cout << "Area: " << area << std::endl;
std::cout << "Circumference: " << circumference << std::endl;
}