Ask your own question, for FREE!
Mathematics 16 Online
OpenStudy (bahrom7893):

Anyone familiar with C++, I have this very easy assignment and I can't get it right.

OpenStudy (bahrom7893):

OpenStudy (bahrom7893):

I keep getting 4, 3 and 3 as a result

OpenStudy (bahrom7893):

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; }

OpenStudy (bahrom7893):

that's my code

OpenStudy (bahrom7893):

ANYONE??? PLEASE HELP!!!

OpenStudy (anonymous):

i don't know c++ that well but it seems like its truncating even though the number is a double

OpenStudy (anonymous):

also you should probably try the computer science section

OpenStudy (phi):

C++ assumes integer arithmetic if you type in just e.g. 4 replace your constant 4 with 4.0

OpenStudy (bahrom7893):

ohhh lol thanks a lot, just got that suggestion from a computer science section!!!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!