[ create a new paste ] login | about

Link: http://codepad.org/rd5Irim7    [ raw code | output | fork ]

C++, pasted on Jul 12:
#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;
}


Output:
1
2
3
The Quadratic Equation: ax^2 + bx = c
Please enter a: 
Disallowed system call: SYS_fork


Create a new paste based on this one


Comments: