Блог пользователя Black_Knight

Автор Black_Knight, 10 лет назад, По-английски

The Following Code should output "Happy Coding" after certain operations, but it is never printed. When n=0.01 and the statement n-=0.01 executes, it prints 5.52024e^-014. Can anyone explain why it occurs and what the remedy is??

#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
int main()
{
    double n;
    n=45.65;
    while(n!=0.00)
    {
        n-=0.01;
        cout<<n<<" "<<endl;
    }

    cout<<"Happy Coding"<<endl;
    return 0;
}

Thanks in Advance.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится