codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> #include <cmath> int main() { std::cout << "The Quadratic Equation: ax^2 + bx = c" << std::endl; std::cout << "Please enter a: "; float a; std::cin >> a; std::cout << "Please enter b: "; float b; std::cin >> b; std::cout << "Please enter c: "; float c; std::cin >> c; float delta = (b * b) - (4 * a * c); if (a == 0) { std::cout << "This is not a quadratic equation! Please try another." << std::endl; } else if (a != 0) { if (delta > 0) { float x1 = (-b + sqrt(delta)) / (2 * a); float x2 = (-b - sqrt(delta)) / (2 * a); std::cout << "We have 2 different solutions are x1 = " << x1 << " and x2 = " << x2 << std::endl; } else if (delta == 0) { float x = -b / (2 * a); std::cout << "We have 2 the same solutions are x = " << x << std::endl; } else if(delta < 0) { std::cout << "No solutions." << std::endl; } } system("pause"); return 0; }
Private
[
?
]
Run code
Submit