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
19 changes: 7 additions & 12 deletions 2-variables/quadratic-formula/quadratic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@
#include <cmath>

int main() {

double a, b, c;
double root1, root2;

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

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

std::cout << "Enter c: ";
std::cin >> c;

root1 = (-b + std::sqrt(b*b - 4*a*c)) / (2*a);
root2 = (-b - std::sqrt(b*b - 4*a*c)) / (2*a);


double root1, root2;
root1 = std::sqrt(b*b - (4*a*c)); //So you just call the function sqrt() one time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that you should name this variable is delta

root2 = (-b - root1)/ (2*a);
root1 = (-b + root1)/ (2*a);

std::cout << "Root 1 is " << root1 << "\n";
std::cout << "Root 2 is " << root2 << "\n";

return 0;

}