Quadratic Equation solver – My calculation is wrong ..

Posted on Updated on

Using the below algorithm:


I wrote a program that would solve any QE as long as variables a, b and c are registered by the user. The magic happens in my function:

Implementation file:

void firstSolution::calculateSquareRoot(int a, int b, int c) {
	quadratic_formula = ((b*b) - (4 * (a*c)));						//ax2 + bx + c = 0
	result[0] = (((b * -1) - (sqrt(quadratic_formula))) / 2);	    //平方根計算する前の +
	result[1] = (((b * -1) + sqrt(quadratic_formula)) / 2); 		//平方根計算する前の ー

My header file is:

// #include "firstSolution.h"

class firstSolution {
	int a_value;
	int b_value;
	int c_value;
	int quadratic_formula;

	int result[2];

	firstSolution();   // コンストラクタ
	~firstSolution();  // デストラクタ

	void enterValues();
	void getValues();
	void calculateSquareRoot(int a, int b, int c);


However, the calculation is wrong somehow .. i need to fix this later


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s