Anyone familiar with C++, I have this very easy assignment and I can't get it right.
I keep getting 4, 3 and 3 as a result
using namespace std; int main() { cout << "Pi approximations: " << endl; double app1, app2, app3; app1 = 4; app2 = 4-4/3+4/5; app3 = 4-4/3+4/5-4/7+4/9; cout << app1 << endl; cout << app2 << endl; cout << app3 << endl; system("pause"); return 0; }
that's my code
ANYONE??? PLEASE HELP!!!
i don't know c++ that well but it seems like its truncating even though the number is a double
also you should probably try the computer science section
C++ assumes integer arithmetic if you type in just e.g. 4 replace your constant 4 with 4.0
ohhh lol thanks a lot, just got that suggestion from a computer science section!!!
Join our real-time social learning platform and learn together with your friends!