Nå nu kan den vist godt lukke
Det virker nu, men aner ikke hvorfor. Den endelige kode ser sådan her ud:
#include <iostream>
#include <math.h>
int main()
{
std::cout << " loesning af ligningen ax^2+bx+c " << std::endl;
int a, b, c, d;
std::cout << "Tal a: ";
std::cin >> a;
std::cout << "Tal b: ";
std::cin >> b;
std::cout << "Tal c: ";
std::cin >> c;
std::cout << "d" << " = " << b << " * " << b << " - " << 4 << " * " << a << " * " << c << " = " << b * b - 4* a * c << std::endl;
std::cin.get();
if((b * b - 4* a * c)<0)
std::cout << "d er mindre end 0, der er ingen løsning" << std::endl;
if((b * b - 4* a * c)==0)
{
std::cout << "d er lig 0, der er en loesning" << std::endl;
std::cout << "x" << " = " << -b << " + " << sqrt ( b * b - 4* a * c ) << " / " << 2 << " * " << a << " = " << ( -b + sqrt( b * b - 4* a * c ) ) / (2 * a) << std::endl;
}
if((b * b - 4* a * c)>0)
{
std::cout << "d er større end 0, der er 2 løsninger" << std::endl;
std::cout << "x1" << " = " << -b << " + " << sqrt ( b * b - 4* a * c ) << " / " << 2 << " * " << a << " = " << ( -b + sqrt( b * b - 4* a * c ) ) / (2 * a) << std::endl;
std::cout << "x2" << " = " << -b << " - " << sqrt ( b * b - 4* a * c ) << " / " << 2 << " * " << a << " = " << ( -b - sqrt( b * b - 4* a * c ) ) / (2 * a) << std::endl;
}
std::cin.get();
}