Aracon
Routinier
Hi ich will ein kleines Programm zur Übung schreiben, es soll mir die Lösungen der Mitternachtsformel berechnen (http://de.wikipedia.org/wiki/Mitternachtsformel)
Aber ab und an kommt nur Müll raus. Hier der Code:
Aber ab und an kommt nur Müll raus. Hier der Code:
Code:
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
float a,b,c;
float x1, x2, *px1, *px2;
bool temp;
bool check(float a, float b, float c);
float mitter(float a, float b, float c);
int get();
double hilf = sqrt(b*b - 4*a*c);
int main()
{
get();
check(a, b, c);
if(temp == 0)
{ cout << "Sorry es gibt keine Lösung!" << endl;
return 0;
}
else
mitter(a, b, c);
cout << "Die Lösungen sind:" << endl << *px1 << "und" << *px2 << endl;
return 0;
}
int get()
{
cout << "a:" << endl;
cin >> a;
cout << "b:" << endl;
cin >> b;
cout << "c:" << endl;
cin >> c;
}
bool check(float a, float b, float c)
{
if(hilf*hilf < 0)
return temp = 0;
else
return temp = 1;
}
float mitter(float a, float b, float c)
{
x1 = ((-b + hilf) / (2*a));
x2 = ((-b - hilf) / (2*a));
px1 = &x1;
px2 = &x2;
}