Invalid Calculations

Im getting invalid answers to the problems. For example if I set B=-3 , A=1 , and C=-4 I get -17 when I should be getting 25. Anyone mind telling me why?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
		int B;
		int A;
		int C;
		cout<<"We Are Going To Calculate The Amount Of Solutions And The Amount Of X Intercepts"<<endl;
		cout<<"Enter B's Value: ";
		cin>>B;
		cout<<"Enter A's Value: ";
		cin>>A;
		cout<<"Enter C's Value: ";
		cin>>C;
		int Answer=B^2-4*A*C;
		cout<<"It Equals "<<Answer<<endl;
		cin.ignore();
		cin.get();
B^2 is not what you think it is. In C++ ^ means XOR. You need to use the pow function from the math library.

Read the section on bitwise operators.
http://cplusplus.com/doc/tutorial/operators/

Here is how to raise a value to a power.
http://cplusplus.com/reference/clibrary/cmath/pow/
You need to use the pow function from the math library.


grrrr.. no you don't.

Don't use pow to square something.

B*B - 4*A*C
thanks for the help Disch
My solution was more general and handles all cases; there is no reason to be growling about anything regardless of which way you choose to solve the problem.
yeah i looked at your method but Disch's was simpler but yours would have worked also
Topic archived. No new replies allowed.