I am trying to use a add function to take the double value and add it with a another double value to get the answer. I use the get method/function to get the answer value. The answer value is only showing in int and not by double. Like for example, 12.0 + 10.0 is equal to 22.0 but when I display the result it only says 22. Here is the code that I am working on...
double x = 0.0;
void addValue(double value)
{
x = value + x;
}
double getValue()
{
return x;
}
int main()
{
addValue(12.0);
addValue(10.0);
cout << getValue() << endl;
return 0;
}
The result of this code is 22 What I am trying to get is 22.0
How can i fixed this without having to use the set precision?