c++ - Why does this code produce strange, unexpected output? -
Why can not I find the right results?
I do not get the proper output of PX, although I have given it name as double, I'm getting some angry numbers-text mashup as a result.
#include & lt; Iostream & gt; using namespace std; Int main () {double one = 0; Double b = 0; Double c = 0; Double x = 0; Cout & lt; & Lt; "Welcome to Lytis! \ NPlease enter one:"; Cin & gt; & Gt; a; Cout & lt; & Lt; "Please enter B:"; Cin & gt; & Gt; B; Cout & lt; & Lt; "Please enter c:"; Cin & gt; & Gt; C; If (a! = 0) {double d = (b * b) - (4 * a * c); } F (d == 0) {double x = - (b) / (2 * a); Double * px = & amp; X; Cout & lt; & Lt; "Solution x =" & lt; & Lt; Pixels; Cin.get (); }
What am I missing?
1) does not compile your code (like d
has not been declared)
2) "Number text mashup" strong> address of X (pointer) that you are printing.
Use the dealer operator *
to indicate the value:
cout & lt; & Lt; "Solution x =" & lt; & Lt; * Pixels; ^^^ here
3) You should check the return value of cin
to be protected against wrong input.
4)
Comments
Post a Comment