-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathEx2_03C.cpp
More file actions
32 lines (25 loc) · 1.07 KB
/
Ex2_03C.cpp
File metadata and controls
32 lines (25 loc) · 1.07 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
// Format specifiers for std::format()
import <iostream>;
import <format>;
import <numbers>; // For the pi constant
#include <cmath> // For the square root function
int main()
{
// 2 square feet pond surface for every 6 inches of fish
const double fish_factor{ 2.0 / 0.5 }; // Area per unit length of fish
const unsigned int inches_per_foot{ 12 };
unsigned int fish_count{}; // Number of fish
double fish_length{}; // Average length of fish
std::cout << "Enter the number of fish you want to keep: ";
std::cin >> fish_count;
std::cout << "Enter the average fish length in inches: ";
std::cin >> fish_length;
fish_length /= inches_per_foot; // Convert to feet
std::cout << '\n';
// Calculate the required surface area
const double pond_area{ fish_count * fish_length * fish_factor };
// Calculate the pond diameter from the area
const double pond_diameter{ 2.0 * std::sqrt(pond_area / std::numbers::pi) };
std::cout << std::format("Pond diameter required for {} fish is {:.2} feet.\n",
fish_count, pond_diameter);
}