Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

bunyonb

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^2-4ac cannot be negative. I am having a hard time with this bit. Could you help me solve this part?

  • one year ago
  • one year ago

  • This Question is Closed
  1. tyteen4a03
    Best Response
    You've already chosen the best response.
    Medals 0

    Is there any code handy?

    • one year ago
  2. bunyonb
    Best Response
    You've already chosen the best response.
    Medals 0

    @tyteen4a03 /* This program takes in the values of the three coefficients a, b, and c as a screen input from the user. It then determines the roots of the quadratic equation using the formula ax^2 + bx + c = 0. The two roots are then outputted using the 'cout' command. */ #include <iostream> #include <cmath> using namespace std; int main(){ /* Declaring and initializing our variables a, b,c a and disc which is short for the discriminant, positive_root and negative_root*/ float a,b,c,disc,positive_root,negative_root; cout << "Enter the 3 coefficients a, b, c : " << endl; cin>>a>>b>>c; if(!a){ if(!b) cout << "Both a and b cannot be 0 in ax^2 + bx + c = 0" << "\n"; else { disc=-c/b; cout << "The solution of the linear equation is : " << d << endl; } } else { disc=b*b-4*a*c; if(d>0) positive_root=(-b+sqrt(d))/(2*a); negative_root=(-b-sqrt(d))/(2*a); cout << "The first root = " << positive_root << endl; cout << "The second root = " << negative_root << endl; } getch(); return 0; }

    • one year ago
  3. bunyonb
    Best Response
    You've already chosen the best response.
    Medals 0

    This is a modified code of someone else's

    • one year ago
    • Attachments:

See more questions >>>

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.