I'm very curious about how does the "term" variable work in the first line of code when it codes: double pi = 0.0, term;
I also am unable to run this code on VSCode IDE Error Code C4578
I can't seem to find an answer on Google, so I came here. On the error of running the code, I tried to change numbers (adding decimal places) because it says its a data conversion problem with abs(). I think its something with abs() only outputing int datatype, is there anyway to fix it?
Thank u so much if you are seeing this, its my first time coding ;)
In double pi = 0.0, term;
, pi = 0.0
and term
are separate items. Equivalent code is double pi = 0.0;
, which defines pi
to be a double
and initializes it to zero, and double term;
, which defines term
and does not specify an initial value for it.
The error “'initializing': conversion from 'double' to 'int', possible loss of data'” is from the line int places = 10.0;
, which specifies a double
value, 10.0
, for an int
object, places
. To eliminate the warning, change this to int places = 10;
.
In C
, abs
is a function for the int
type. The fact that this code uses it with a double
operand, term
, indicates this is C++ code, and the file name, L2.1-2.3.cpp
, also indicates this is C++ code. You seem to have requested your compiler to compile it as C code, which is why it gives you the message “'abs': conversion from 'double' to 'int', possible loss of data”. You should change whatever setting is telling your compiler to compile this as C code.