Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions HomeWork1/1HwKobzystyiMaksym
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это лишнее, понимаю что в качестве примеров для дз это ок, но для будущего старайтесь такие вещи просто избегать. конструкция типа using namespace std; может привести к неприятным сюрпризам


int main() {
double a;
double b;
double c;
double x;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

старайтесь обьявлять переменные по мере их использования. Т.е. не обьязательно все сразу обьявлять вначале функции.
Например

double a;
std::cout << "Enter a: ";
std::cin >> a;

double b;
std::cout << "Enter b: ";
std::cin >> b;

std::cout << "Enter a: ";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем вы вначале тогда подключали using namespace std;
если вы пишите std::cout
выражение using namespace std; пишут для того чтобы лишний раз не писать std при использования функционала со стандартной библиотеки

std::cin >> a;
std::cout << "Enter b: ";
std::cin >> b;
std::cout << "Enter c: ";
std::cin >> c;
if ((b * b - 4 * a * c) >= 0) // If >=0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

у вас выражение (b * b - 4 * a * c) повторяеться в трех местах
сделайте константу и используйте ее в коде

auto kDesc = (b * b - 4 * a * c);

{
x = (-1 * b + sqrt(b * b - 4 * a * c)) / (2 * a);
std::cout << "1st root " << x << std::endl;
x = (-1 * b - sqrt(b * b - 4 * a * c)) / (2 * a);
std::cout << "2nd root " << x << std::endl;
} else {
std::cout << "Less 0" << endl;
}

int value;
cin >> value;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно еще попробовать std::cin.get()
должно работать

return 0;
}