Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #define _USE_MATH_DEFINES
- #include <math.h>
- using namespace std;
- double calculate_area(double length, double width) {
- return length * width;
- }
- double calculate_area(double radius) {
- return M_PI * radius * radius;
- }
- int main()
- {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- double a{}, b{}, r{};
- while (true) {
- cout << "Введіть довжину прямокутника: ";
- cin >> a;
- if (cin.fail() || a <= 0) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Довжину прямокутника було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- while (true) {
- cout << "Введіть ширину прямокутника: ";
- cin >> b;
- if (cin.fail() || b <= 0) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Ширину прямокутника було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- while (true) {
- cout << "Введіть радіус кола: ";
- cin >> r;
- if (cin.fail() || r <= 0) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Радіус кола було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- cout << "Площа прямокутника: " << calculate_area(a, b) << endl;
- cout << "Площа круга: " << calculate_area(r) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement