Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double quadplus(float a, float b, float c);
  7. double quadminus(float a, float b, float c);
  8.  
  9. int main()
  10. {
  11. double a, b, c;
  12. double discriminant;
  13.  
  14. cout << "Please Enter variables for a, b, and c." << endl << endl;
  15. cout << "Enter number for variable a." << endl << endl;
  16. cin >> a;
  17. cout << "Enter number for variable b." << endl << endl;
  18. cin >> b;
  19. cout << "Enter number for variable c." << endl << endl;
  20. cin >> c;
  21. discriminant = (b * b) - (4 * a * c);
  22.  
  23. if(discriminant == 0)
  24. cout << quadplus(a,b,c) << endl;
  25. else if(discriminant > 0)
  26. cout << quadplus(a,b,c) << endl;
  27. else if(discriminant < 0)
  28. cout << quadminus(a,b,c) << quadplus(a,b,c) << endl;
  29.  
  30. return 0;
  31. }
  32.  
  33. double quadplus(float a, float b, float c)
  34. {
  35. return ((-1 * b) + (sqrt(( b * b) - (4 * a * c))) / (2 * a));
  36. }
  37. double quadminus(float a, float b, float c)
  38. {
  39. return ((-1 * b) - (sqrt(( b * b) - (4 * a * c))) / ( 2 * a));
  40. }
  41.  
  42. cout << quadplus << endl;
  43.  
  44. cout << quadplus(a, b, c) << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement