I have this code in my program: (I included the cout statements for debugging purposes)
cout << "b: " << b << "\na: " << a;
constant[0] = (-b / (2 * a));
cout << "\nconstant: " << constant[0] << endl;
The output I get is:
b: -4
a: 3
constant: 0
Whereas I’m trying to make constant[0] equal to -(-4)/(2 * 3), or 0.6666…
What am I doing wrong with the formula I put there?
Undoubtably you have
aandbdefined as integers, causing your whole formula to be done in integer math. Either define them as floating point numbers or do something like this:which forces the math to be done in floating point.