Funktioner ?(måske) nybegynder hjælp tak!
Hey der ude, jeg er mere eller mindre lige begyndt på C++, og ville så øve mig lidt i brugen af funktioner, men jeg kan bare ikke få det til at virke.Hvad er det lige jeg gør forkert her under ??
Jeg har prøvet at lave en andengrads lignings løser.
Sorry hvis det er lidt rodet, eller ligende, men er jo ny hehe.
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
float x1 = 0;
float x2 = 0;
float x3 = 0;
float d = 0;
float a = 0;
float b = 0;
float c = 0;
void to(float a, float b, float d)
{
cout << "Der er funder to laesninger" << endl;
d = sqrt (d);
x1 = (((b*-1) + d) / (2 * a));
x2 = (((b*-1) - d) / (2 * a));
cout << "X1 =\t" << x1 << endl;
cout << "X2 =\t" << x2 << endl;
}
void en(float a, float b)
{
cout << "Der er fundet en laesning" << endl;
x3 = ((b*-1)/(2*a));
cout << "x =\t" << x3 << endl;
}
int main()
{
cout << "Andengrads ligninger\n";
cout << "Indtast A\t" << endl; // Input af andengrads ligningens abc værdier.
cin >> a;
cout << "Indtast B\t" << endl;
cin >> b;
cout << "Indtast C\t" << endl;
cin >> c;
cout << "d = " << b << "^2 - 4 * " << a << " * " << c << endl; // udskriver ligningen for d
d = (pow(b,2) - (4 * a * c));; // udregner d (pow() er = ^)
cout << "d = " << d << endl; // udskriver d
if (d > 0)
{
void to(float a, float b, float d);
}
else if (d = 0)
{
void en(float a, float b);
}
else if (d < 0)
{
cout << "Der er ingen loesninger" << endl;
}
system("PAUSE");
return 0;
}