PDA

View Full Version : Need help with exiting code error



Chrona
18th October 2012, 19:55
So I wrote a program that worked in Microsoft visual c++ and when I loaded it into Qt Creator and try to run the program. I get the error "exited with code 1073807364". This program is pretty simple and solves quadratic equations but I just don't know how to fix this problem. Any help would be appreciated please and thank you. Here is my code:


#include <iostream>
#include <cmath>
#include <complex>
#include <queue>
#include <windows.h>
#include <QtGui/QApplication>
#include "mainwindow.h"

using namespace std;

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();


double x_squared, x, c;

cout << "Enter the value for x squared..." <<endl;
cin >> x_squared;
cout << "Enter the value for x..." <<endl;
cin >> x;
cout << "Enter the value for c..." <<endl;
cin >> c;



double discriminant = (pow(x,2) - 4*x_squared*c);
double positive_root = (((-x + sqrt(discriminant))/(2*x_squared)));
double negative_root = (((-x - sqrt(discriminant))/(2*x_squared)));


if (discriminant == 0)
{
cout << "\n\nThe discriminant is ";
cout << discriminant << endl;
cout << "The equation has a single root.\n\n";
}

else if (discriminant <0)
{
cout << "\n\nThe discriminant is ";
cout << discriminant << endl;
cout << "The equation two complex roots.\n\n";
}

else
{
cout << "\n\nThe discriminant is ";
cout << discriminant << endl;
cout << "The equation two real roots.\n\n";
}


cout << "The roots of the quadratic equation are x = ";
cout << negative_root;
cout << ", ";
cout << positive_root << endl;

return a.exec();
}

Ashkan_s
18th October 2012, 20:31
Does this sqrt function that you have used accepts negative values? If not check discriminant value before passing it to sqrt. Also make sure x_squared is not zero.

Chrona
29th October 2012, 20:11
thank you very much.