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

  • SEARCH
  • Home
  • 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 8583333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:30:38+00:00 2026-06-11T21:30:38+00:00

I am trying to run the following program and it works but when I

  • 0

I am trying to run the following program and it works but when I enter a value that is more than 6 decimal places it keeps getting rounded/truncated e.g. 2.999999 –> 3. How do I set it so it stops doing this?

int main()
{

    double n=0, x=0; 

    while (cin >> n >> x) //will keep going until an integer is not entered
    {
       cout << "You entered the two integers " << x << " and " << n << endl;

       if (x-n <= (1.0/10000000) && n-x <= (1.0/10000000)) 
          cout << "The numbers are almost equal" << 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-06-11T21:30:40+00:00Added an answer on June 11, 2026 at 9:30 pm

    You can change precision of the values that you print by using std::setprecision:

    cout << "You entered the two integers " << setprecision(20) << x
         << " and " << n << endl;
    

    Link to ideone.

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

Sidebar

Related Questions

Trying to run my program in FreeBSD OS, I have the following results: $
When i am trying to run my program it is giving the following error
I am trying to run the following code that I found marked as correct
I'm trying to run the following query, but am not sure how to limit
I have a program that works fine on VS2008 and Vista , but I'm
I'm trying to write a program that will run a program on a remote
Am trying to run the following python program import re regex=re.compile(http...imgs.xkcd.com.comics.[\\S]*.[jpg|png]) f=open('out.txt') for a
when I trying to run following code. var result = from c in db.brand
Trying to run the following command in php to run powershell command... the following
I am trying to run the following to extract the text from all the

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.