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 8487077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:07:54+00:00 2026-06-10T21:07:54+00:00

I edited a C program for my assignment, previously there wasn’t typecasting and the

  • 0

I edited a C program for my assignment, previously there wasn’t typecasting and the iteration stopped at i=1, now with the typecasting it stops at i=6.

Any ideas why? Thanks in advance!

int main(void)
{

    int i = 0;
    double d = 0.0;

    while ( (i == (int) (d * 10)) && (i < 10) )
    {
        i = i + 1;
        d = (double) (d + 0.1);
        printf("%d %lf\n", i, d);
    }

    printf("%d %lf\n", i, d);

    getch();

    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-10T21:07:56+00:00Added an answer on June 10, 2026 at 9:07 pm

    As has been stated many times before, the reason this doesn’t work is that binary floating point numbers cannot represent all decimal floating point binary numbers, it just isn’t possible. To read more, check out this really great article:

    What Every Programmer Should Know About Floating-Point Arithmetic

    Now, on the more practical side of things, when using floating point and comparing it to another number, you should almost always round the value or use an epsilon value, like this:

    if (ABS(doubleValue - intValue) < 0.00001) // 0.00001 is a margin-of-error for floating point arithmetic
        // the two numbers are even (or close to it)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi, there is a Java program edited and compiled using Netbeans 6.9.1. After running
Edited by OP. My program is in need of a lot of cleanup and
Edited Question: This should be clear. using System; namespace UpdateDateTimeFields { class Program {
My program/process exited abnormally? I doubt something is wrong with the following code: There
I'm working a program where there's an Airline class. The Airline class contains a
I have edited this question but at the bottom of the program I have
Previously my program was working well on different sizes of screen and devices. After
Working on a class assignment in C#, I came across a program crash without
EDITED because question is about same program. I'm trying to take the top fifty
I'm working on a program with DataGridViews . In one DatagridView there is a

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.