Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Hu
- #include <iostream>
- #include <cmath>
- using namespace std;
- double positiveCalc(double a, double b, double c){
- double D = (b * b) - (4 * a * c);
- double resultOne = (-b + sqrt(D)) / (2 * a);
- return resultOne;
- }
- double negativeCalc(double a, double b, double c){
- double D = (b * b) - (4 * a * c);
- double resultTwo = (-b - sqrt(D)) / (2 * a);
- return resultTwo;
- }
- int main()
- {
- double a;
- double b;
- double c;
- double D;
- double firstSolution;
- double secondSolution;
- cout << "Please enter the values of a, b, and c: ";
- cin >> a >> b >> c;
- D = (b * b) - (4 * a * c);
- firstSolution = positiveCalc(a, b, c);
- secondSolution = negativeCalc(a, b, c);
- if(D > 0){
- cout << "There are 2 solutions." << endl << endl << "The solutions are: " << firstSolution << " and " << secondSolution;
- }
- else if (D == 0){
- cout << "There is 1 solution." << endl << endl << "The solution is: " << firstSolution;
- }
- else{
- cout << "There is no solution.";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement