A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 4 years ago
I was asked to write a program that finds the solutions, if any, to a given quadratic equation. My code is below. I have two issues: First When i input for example, a=3, b=4, c=5 the result prints" The roots are nan and nan" Secondly, I am to ensure that division by 0 is not permitted and the discriminant b^24ac cannot be negative. I am having a hard time with this bit. Could you help me solve this part?
anonymous
 4 years ago
I was asked to write a program that finds the solutions, if any, to a given quadratic equation. My code is below. I have two issues: First When i input for example, a=3, b=4, c=5 the result prints" The roots are nan and nan" Secondly, I am to ensure that division by 0 is not permitted and the discriminant b^24ac cannot be negative. I am having a hard time with this bit. Could you help me solve this part?

This Question is Closed

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0HERE IS MY CODE: #include <iostream> #include <cmath> using namespace std; int main(){ /* Here I have initialized some variables a,b and c that you would see in a standard quadratic equation. positive_root and negative_root are the roots you get when using the quadratic formula to solve a quadratic equation given the values of a,b and c */ double a, b, c, positive_root, negative_root; cout<<" enter value of a,b and c : "<<endl; cin>>a>>b>>c; // using the functions sqrt() and pow(), we positive_root= (b + sqrt(( pow(b,2) 4*a*c)))/ 2*a ; negative_root= (b  sqrt(( pow(b,2) 4*a*c)))/ 2*a ; cout << " The roots are:"<<positive_root<< " and "<< negative_root<<endl; return 0; }
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.