0

I was trying to exclude my quadratic equations from my main body of code and now it's returning hexadecimal numbers... the numbers are returned quite randomly, they change in value about once every 3-10 times you run the program even though the variables are constant. This far surpasses my knowledge of C++.

I'd ideally like to return the roots of the quadratic equation in the double data type and base 10.

The last commented out bit is just to show you what I've initially done though is mostly redundant.

Thanks in advance.

#include <iostream> #include <cmath> using namespace std; double a,b,c,bsq; double quadpos() { double quadpos = (-b+(sqrt((bsq)-4.0*a*c)))/(2.0*a); double a=1.0,b=2.0,c=1.0; double bsq = pow(2.0,2); return quadpos; } double quadneg() { double quadneg = (-b-(sqrt((bsq)-4.0*a*c)))/(2.0*a); return quadneg; } int main() { // 4a) cout << /*" - Question 4 - \n\n" << "Part A\n" << */quadpos << "\n" << quadneg << std::endl; /*float a = 5.0, b = 7.0, c = -8.0; int bsq; bsq = pow(b,2); double quadpos = (-b+(sqrt((bsq)-4.0*a*c)))/(2.0*a), quadneg = (-b-(sqrt((bsq)-4.0*a*c)))/(2.0*a); cout << a << "\n" << b << "\n" << c << "\n" << bsq << "\n" << quadpos << "\n" << quadneg << endl; The above line is used for troubleshooting cout << "The roots of the quadratic equation 5x^2 + 7x - 8 are " << quadpos << " and " << quadneg << ".\n" << "The roots are the values of the x variable when the equation, 5x^2 + 7x - 8 is equal to 0.\n" << endl; */ } 
1
  • Please note the randomly changing number being the main issue here. Thanks Commented Oct 3, 2013 at 0:13

1 Answer 1

1
cout << /* ... */ quadpos << "\n" << quadneg << std::endl; ^^^^ ? 

You are printing functions directly and getting their addresses (they are interpreted as function pointers in this context). Instead of quadpos you want quadpos().

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the extremely quick reply. Will work on it and post if I get stuck. :) IT WORKS :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.