clrscr() is not standard, it should be avoided.
A semicolon is still missing here:
Code:
float a, b, c, R1, R2; //variables and constants used;
and another one here:
I don't know what that getch() is doing there (are you running the program by double-clicking a .exe file on windows, and want to stop the screen from closing after the calculation?), I think that's a C function, use cin.get() if you must.
You're also missing * between 4, a, c on this line:
Code:
float D = b*b - 4*a*c;
And you're missing a "<<" on this line:
Code:
cout<< "R1 is=" << (-b + sqrt(D))/(2*a);
Now a couple of style points:
Mainly, indentation, when using spaces instead of tabs (which I recommend), choose a set number of spaces to use for each indentation level, and stick with it (I recommend sets of 4 spaces, which it appears you are mostly using). The lines in red are indented incorrectly:
Code:
if (D>=0)
{
cout<< "R1 is=" (-b + sqrt(D))/(2*a);
cout<< "R2 = (-b - sqrt(D))/(2*a);
}
else
cout<< "no real roots exist"<<endl;
getch()
Also with this code, I don't have a problem with omitting the braces for single statements in if/else blocks, but if any block in the if/else sequence requires braces, I say they should all have braces:
Code:
if (D>=0)
{
cout<< "R1 is=" (-b + sqrt(D))/(2*a);
cout<< "R2 = (-b - sqrt(D))/(2*a);
}
else
{
cout<< "no real roots exist"<<endl;
}
getch()
I think this looks ugly:
Code:
cout<< "Enter b=";
cin>> b;
I would put spaces on both sides of "<<" and ">>":
Code:
cout << "Enter b=";
cin >> b;
In fact I would do that for arithmetic operators as well, but that's getting down to my personal taste:
Code:
float D = b*b - 4*a*c; // bad
float D = b * b - 4 * a * c; // good