Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:17:28+00:00 2026-05-31T11:17:28+00:00

Is it possible to do a while loop in C++ until a decimal reaches

  • 0

Is it possible to do a while loop in C++ until a decimal reaches a certain precision? I want to do a long calculation for arctan and then pi and I want the loop to run until pi is calculated to the 10th decimal place using the formula pi=4(arctan (1.0)). I’m manually calculating arctan using the taylor series formula. I know there are built in functions for these calculations but this is a homework assignment so I have to do it this way. I’m not looking for the solution to the problem, just whether or not a loop using precision is possible. Thanks!

Edit:

I’m still stuck with this! I can’t come up with a proper argument for the while loop, even after going over everybody’s hints. Really need help. Here’s the code I have come up with:

#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main(void)
{
 int i;
 long double result;
 long double pi;
 int y=3;
 int loopcount=0;
 long double precision;

   cout<<"Start\n";

   result=1-(pow(1,y)/y);

  do
    {
     y=y+2;
     result=result+(pow(1,y)/y);
     y=y+2;
     result=result-(pow(1,y)/y);

      pi=4*(result);
      precision=(pi*(pow(10,11))/10);

      loopcount++;
    }
  while(//This is the problem!);

  cout<<"Final Arctan is:"<<endl;
     cout<<setprecision(20)<<result<<endl;
  cout<<"Final Pi is:"<<endl;
       cout<<setprecision(9)<<pi1<<endl;
  cout<<"Times looped:"<<endl;
       cout<<loopcount<<endl;

return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:17:29+00:00Added an answer on May 31, 2026 at 11:17 am

    As far as I remember, you can figure out the precision by checking the improvement over the previous iterations. If the 10th decimal place gets stable, break the loop.

    to get the kth decimal digit of n, multiply it by 10 to the power of k and get the least significant digit. For example, to get the 2nd decimal digit 7 out of 3.47, multiply by 100 to get 347 and get the 7 by 347 % 10.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to wait for user touch inside a while loop? I mean,
is it possible to generate an eventhandler while running? I want to do something
Possible Duplicate: Dynamically Growing an Array in C++ I want to create a loop
I want to know if it is possible to end a for loop in
I wanted to keep my logging statements as short as possible while preventing console
I would like to use Visual Studio 2008 to the greatest extent possible while
Possible Duplicates: Do-While and if-else statements in C/C++ macros do { … } while
Possible Duplicate: Modifying .NET Dictionary while Enumerating through it I have a dictionary object
While it is possible to generate PowerPoint presentations automatically using Office Automation , this
Possible Duplicate: Class construction with initial values While I was looking at c++ example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.