Hey How do you go about debugging? like tips and tricks?
I have been looking at my code (below) for like an hour and cant figure out what i have done wrong.....
#include <fstream> // Header File for File Reading
#include <iostream> // Header File for General I/O-put
#include <math.h>
using namespace std; // Use namespacing
int main()
{
ifstream in_stream;
ofstream out_stream;
int a(0), b(0), c(0), Lasta(0), Lastb(0), Lastc(0), counter(0);
double bsqrd, fourac, root, root1, root2;
in_stream.open("inputfile.txt");
while (1)
{
Lasta=a; Lastb=b; Lastc=c;
in_stream >> a >> b >> c;
if (a==Lasta && b==Lastb && c==Lastc){break;}
// calculations for quadratic equation
bsqrd = b*b;
fourac = 4*a*c;
root = sqrt(bsqrd - fourac);
root1 = (-b + root)/4;
root2 = (-b - root)/4;
NumberOfPositiveRoots(root1, root2); // counting positive roots function
cout << "the three values for this quadratic are" << " " << a << " " << b << " " <<c << endl;
cout << "The value of x1 is: " << root1 << endl;
cout << "The value of x2 is: " << root2 << endl;
cout << counter << "of the x values are positive." << endl;
}
in_stream.close();
return 0;
}
void NumberOfPositiveRoots(double first, double second) // function for positive roots
{
int counter = 0;
if (first >= 0)
{
counter++;
}
if (second >= 0)
counter++;
}
return counter;
}