OK, so I have done a bit more progress (see code)...but I'm having trouble with the call for function line:
discriminant=dis_calc(?????); //calling function
do I put a, b, c into the function, or something else?
Thanks in advance for any help!
Code:
//
#include "stdafx.h"
#include<iostream> //required for cout. endl.
#include<fstream>//Required for ifstream, ofstream
#include<cmath> //required for acos().
using namespace std;
double dis_calc(double double double); //Function Prototype
int _tmain(int argc, _TCHAR* argv[])
{
//Declare variables
double a, b, c, discriminant;
double r1, r2;
ifstream fin;
ofstream report;
//prompt user for name of input file
/*cout<<"enter the name of the input file";
cin>>filename;*/
//Open file and read first data line (a, b, c)
fin.open("quad.txt");
if(fin.fail() ) //open failed
{
cerr<<"File quad.txt could not be opened";
exit(1); //end execution of the program
}
while(!fin.eof())
{
fin >> a >> b >> c;
//Calculate discriminant
discriminant=dis_calc(?????); //calling function
cout << discriminant << endl;
if(discriminant>0)
{
r1=(-1*b+sqrt(discriminant))/(2*a);
r2=(-1*b-sqrt(discriminant))/(2*a);
cout<<"r1="<<r1<<"\n";
cout<<"r2="<<r2<<"\n";
cout<<"there are two distinct roots";
}
else if(discriminant==0)
{
r1=(-1*b)/(2*a);
cout<<"r1="<<r1<<"\n";
cout<<"there is exactly one distinct real root";
}
else
{
discriminant=-1*discriminant;
cout<<"No real roots";
}
cout<<"\n";
system("pause");
}
return 0;
}
double dis_calc(double a, double b, double c)
{
double discriminant=((b*b)-4*a*c);
return discriminant;
}