-2
#include <iostream>

using namespace std;

int main (void) {
    float a=5/9;
    cout << a;
}

This code prints 0 and not 0.555 - what is the problem? Any help appreciated.

StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458

1 Answers1

0
5/9

is a division of two integers and its result is 0. If you want the operation done in floats then at least one operand has to be a float:

5/9.f
StoryTeller - Unslander Monica
  • 165,132
  • 21
  • 377
  • 458
Swordfish
  • 12,971
  • 3
  • 21
  • 43