I am teaching myself C++, the problem I have to answer is
In Mathematics, the quantity of b^2-4ac is called the "discriminate." Write a program that asks the user for values of a, b , and c and displays no roots if the discriminant is negative, one root if the discriminant is zero and two roots if the discriminate is positive.
My code looks like this so far.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
double a,b,c,d;
cout<<"Enter the Value for a:"<<endl;
cin>>a;
cout<<"Enter the Value for b:"<<endl;
cin>>b;
cout<<"Enter the Value for c:"<<endl;
cin>>c;
cout<<(b*b-4*a*c)<<endl;
if ( < 0)
cout<<"No Roots"<<endl;
if ( = 0)
cout<<"One Root"<<endl;
if ( > 0)
cout<<"Two Roots"<<endl;
system("PAUSE");
return 0;
}
I need to know how to decide a variable by an equation. I hope that makes sense
#include <iostream>
#include <cstdlib> //(Header changed)
usingnamespace std;
int main(int argc, char *argv[])
{
double a, b, c, d;
cout << "Enter the Value for a:" << endl;
cin >> a;
cout << "Enter the Value for b:" << endl;
cin >> b;
cout << "Enter the Value for c:" << endl;
cin >> c;
//Your fine up to here...
d = b*b - 4*a*c; //Store the discriminate into variable d
cout << d << endl; //(Line changed)
if ( d < 0 ) //I.e. "if the discriminate is less then 0"
cout << "No Roots" << endl;
if ( d == 0) //(If statement changed)
cout << "One Root" << endl;
if ( d > 0 ) //(If statement changed)
cout << "Two Roots" << endl;
system("PAUSE"); //Why is this line here? Do you need it?
return 0;
}