Adding 2 double values returns an Integer ?

I'm adding 2 double values but the output is an integer value.

#include<iotream>

int main()
{

double d = 4.0;
double sd = 0;

cin >> sd;

std::fixed;
cout << std::setprecision(2) << d + sd << endl;
return 0;
}
Input : 4.0 + 4.0
Output : 8 //Expected Output 8.0

Can anyone help me understand what am I missing ?
Last edited on
Well you're missing the half-dozen or so other lines which would be a nice complete program we can copy/paste/test for ourselves.

A couple of random lines out of context, and a "I did foo" doesn't really tell much.
Hey Salem,

I've updated the post.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <iomanip>

int main()
{
    const double d = 4.0;

    double sd = 0;
    std::cin >> sd;

    std::cout << std::fixed << std::setprecision(2)
              << d << " + " << sd << " == " << d+sd << '\n' ;
}

http://coliru.stacked-crooked.com/a/55d3b52acab8f759
Thanks for the solution JL Borges.
Topic archived. No new replies allowed.