Advertisement
TheBeastOver9000

Untitled

Apr 29th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <conio.h>
  5. #include <stdlib.h>
  6. #include <locale>
  7.  
  8. //Quadratic equation solver
  9.  
  10. using namespace std;
  11.  
  12. int D, a, b, c, x1, x2;
  13. double qq;
  14. bool foo;
  15.  
  16. int main(){
  17.     cout << "Sqrt is a sqare root\n";
  18.     cout << "Enter a\n";
  19.     cin >> a;
  20.     cout << "Enter b\n";
  21.     cin >> b;
  22.     cout << "Enter c\n";
  23.     cin >> c;
  24.     D = (pow(b, 2) - (4 * a * c));
  25.     cout << "Discriminant = " << D << "\n";
  26.     if (D < 0){
  27.         cout << "X1, X2 = varnothing\n";
  28.         cout << "Press Enter to continue\n";
  29.         cin.get();
  30.         return 0;
  31.     }
  32.     else if (D == 0){
  33.         x1 = (b * -1) / (2 * a);
  34.         x2 = x1;
  35.     }
  36.     else{
  37.         qq = sqrt(D);
  38.         if (D / qq == qq){
  39.             x1 = ((b * -1) - qq) / (2 * a);
  40.             x2 = ((b * -1) + qq) / (2 * a);
  41.         }
  42.         else{
  43.             a = a * 2;
  44.             cout << "X1 = -" << b << " - sqrt of" << D << " / " << a << "\n";
  45.             cout << "X2 = -" << b << " + sqrt of" << D << " / " << a << "\n";
  46.             cout << "Press Enter to continue\n";
  47.             cin.get();
  48.             return 0;
  49.         }
  50.     }
  51.    
  52.     cout << "X1 = " << x1 << "\nX2 = " << x2 << "\n";
  53.     cout << "Press Enter to continue\n";
  54.     cin.get();
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement