Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update quadratic.cpp #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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

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;

}