Quadratic equation

okay what's wrong with this program ? it shows me delta but not more ..i want to see x1,x2 too ..
#include <iostream>
#include <stdio.h>;
#include <math.h>;
void main()
{

int a,b,c;
float x1,x2,delta,d;

cout<<"Scrieti a = ";
cin>>a;
cout<<"Scrieti b = ";
cin>>b;
cout<<"Scrieti c = ";
cin>>c;
if (a==0)
g<<"Ecuatie de gradul I";
else
{
delta = pow(b,2)-4*a*c;
if (delta>0)
{
x1 = (-b+sqrt(delta))/(2*a);
x2 = (-b-sqrt(delta))/(2*a);
cout<<"x1 = "<<x1<<" x2 = "<<x2;
}
else
if (delta==0)
{
g<<"ecuatia are doar o solutie";
g<<"x1=x2="<<-b/(2*a);
}
else
g<<"ecuatia nu are solutii vezi doamne in multimea numerelor reale"
}
f.close();
g.close();
}
there are some romanian words in there but i dont think it will cause any problem :)
Last edited on
g<<"Ecuatie de gradul I";
What's g? How is this even compiling?
Please put code in code tags. It makes it easier to read.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <stdio.h>;
#include <math.h>;
void main()
{

int a,b,c;
float x1,x2,delta,d;

cout<<"Scrieti a = ";
cin>>a;
cout<<"Scrieti b = ";
cin>>b;
cout<<"Scrieti c = ";
cin>>c;
if (a==0)
g<<"Ecuatie de gradul I";
else
{
delta = pow(b,2)-4*a*c;
if (delta>0)
{
x1 = (-b+sqrt(delta))/(2*a);
x2 = (-b-sqrt(delta))/(2*a);
cout<<"x1 = "<<x1<<" x2 = "<<x2;
}
else
if (delta==0)
{
g<<"ecuatia are doar o solutie";
g<<"x1=x2="<<-b/(2*a);
}
else
g<<"ecuatia nu are solutii vezi doamne in multimea numerelor reale"
}
f.close();
g.close();
}
this is the first exercise i ever done in c ++ ...and it seems like i`m kinda pathetic :)
i would appreciate a working program for quadratic equation tho :)
If this is the first exercise you've ever done, you might want to start with something you know will compile and work up from that.
How does it show you delta? I don't see an output statement for delta.

What are f and g? You close them at the end of the program as if they were streams, but you haven't defined them earlier in the program as streams and opened them.

You have defined the variable d, but never use it.

I don't think you have a closing brace for the end of the main routine.

Topic archived. No new replies allowed.