i dont know y my program is not working on linux system.
double a,b,c,x1,x2;
char x;
cout<<"enter the value of a=";
cin>>a;
cout<<"enter the value of b=";
cin>>b;
cout<<"enter the value of c=";
cin>>c;
cout<<"the quadratic equation is"<<a;
cout<<"*x*x+"<<b;
cout<<"*x+"<<c<<endl;
if
(a==0 && b==0)
cout<<"not a valid equation";
if
(a==0 && b!=0)
{
x1=-(c/b);
cout<<endl;
cout<<"root="<<x1;
cout<<endl;
}
if ((b*b-4*a*c)>0)
{
x2=(b*b)-(4*a*c);
x1=-b+sqrt(x2);
cout<<"root="<<x1<<endl;
}
if ((b*b-4*a*c)<0)
{
cout<<"not a real root"<<endl;
}
system("pause");
return 0;
}
i have type this code, there is no error but it says code is not working?
can anyoneo found the mistake?
What exactly says that the "code is not working"? What are the requirements that we should test against?
A quadratic equation can have two roots (-b +/- sqrt(b*b - 4ac)) / (2a), but you're only printing one. That's probably the first issue. You also aren't dividing by 2a.
Write a program that calculates the real solution of the quadratic equation: a ∗ x2 + b ∗ x + c = 0
! First, read in the values for the parameters a, b, c (all of type float).
Then, the program should calculate and display the solution considering the following scenarios:
! a = 0 and b = 0 ⇒ display error message "invalid input"
! a = 0 and b ̸= 0 ⇒ x = −c
b
! (b2 − 4 ∗ a ∗ c) < 0 ⇒ display error message "no real solution"
! (b2 − 4 ∗ a ∗ c) ≥ 0 ⇒ x1 = −b+√b2−4∗a∗c
2∗a , x2 = −b−√b2−4∗a∗c
2∗a
Hint: The C++-function for y = √x is y = sqrt(x). Include math and use the function as in the example below:
#include <iostream>
#include <cmath>
using std::cout;
int main()
{
double a = 144.0; // define and initialize variable a
cout << "Result = " << sqrt(a) << endl; // display square root of a
return 0;
}
can you access it more normally using winscp?
pictures (esp when poorly cropped an scaled) often take up an insane amount of space for their contents. They also are difficult to police for ads or inappropriate content. An image of text is right on up there with XML for turning a couple of bytes into a couple of MILLION bytes.
and a lot of us can't (or will not) access third party sites for files.
get a local copy of your code, fix it in cygwin or something, and push it out to unix server once its working and done. Don't try to code on an unfriendly (not set up for it) server.
// ...
elseif ( b*b - 4*a*c < 0)
{
// no real solution
}
else
{
/// real solution(s)
}
Coding aside, I suggest setting up a compiler on your own computer so that you don't have to go through the pain of remoting in to test code. Compilers like GCC are supported on all major OSes.