Advertisement
Guest User

a

a guest
Sep 15th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. //Hu
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double positiveCalc(double a, double b, double c){
  7. double D = (b * b) - (4 * a * c);
  8. double resultOne = (-b + sqrt(D)) / (2 * a);
  9. return resultOne;
  10. }
  11.  
  12. double negativeCalc(double a, double b, double c){
  13. double D = (b * b) - (4 * a * c);
  14. double resultTwo = (-b - sqrt(D)) / (2 * a);
  15. return resultTwo;
  16. }
  17.  
  18. int main()
  19. {
  20. double a;
  21. double b;
  22. double c;
  23. double D;
  24. double firstSolution;
  25. double secondSolution;
  26.  
  27. cout << "Please enter the values of a, b, and c: ";
  28. cin >> a >> b >> c;
  29.  
  30. D = (b * b) - (4 * a * c);
  31. firstSolution = positiveCalc(a, b, c);
  32. secondSolution = negativeCalc(a, b, c);
  33.  
  34. if(D > 0){
  35. cout << "There are 2 solutions." << endl << endl << "The solutions are: " << firstSolution << " and " << secondSolution;
  36. }
  37. else if (D == 0){
  38. cout << "There is 1 solution." << endl << endl << "The solution is: " << firstSolution;
  39. }
  40. else{
  41. cout << "There is no solution.";
  42. }
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement