Advertisement
TheBeastOver9000

My School Project

May 18th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 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, d;
  13. double qq;
  14.  
  15. int main(){
  16.     start:
  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 << "D = " << D << endl;
  26.     if (D < 0){
  27.         cout << "X1, X2 = varnothing\n";
  28.         system("pause");
  29.         return 0;
  30.     }
  31.     else if (D == 0){
  32.         x1 = (b * -1) / (2 * a);
  33.         x2 = x1;
  34.     }
  35.     else{
  36.         qq = sqrt(D);
  37.         if (D / qq == qq){
  38.             x1 = ((b * -1) - qq) / (2 * a);
  39.             x2 = ((b * -1) + qq) / (2 * a);
  40.         }
  41.         else{
  42.             a = a * 2;
  43.             cout << "X1 = -" << b << " - sqrt of" << D << "/ " << a << "\n";
  44.             cout << "X2 = -" << b << " + sqrt of" << D << "/ " << a << "\n";
  45.             system("pause");
  46.             return 0;
  47.         }
  48.     }
  49.  
  50.     cout << "X1 = " << x1 << "\nX2 = " << x2 << "\n";
  51.     system("pause");/*
  52.     cout << "\nDo you want to do it again?" << "\nIf yes then enter 1, else enter 0" << endl;
  53.     cin >> d;
  54.     if (d == 1)*/
  55.         goto start;
  56.     //else
  57.         return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement