0
#include<iostream>
using namespace std;

int main()
{
    double x = 0.625, E = 0.0001;
    double value[2] = { 1 / x, 0 };
    for (int count = 0; ; count++)
    {
        value[1] = ((3 / 2) * value[0]) - ((1 / 2) * x * pow(value[0], 3));
        cout << value[1] << value[0];
        value[0] = value[1];
    }

}

Why doesn't value[1] change its number, if there is the instruction that does some calculations?(the eighth line)

1 Answers1

2

(3 / 2) and (1 / 2) are integral operations and do not produce fractional results. They do not produce 1.5 and 0.5 like you expect; they return 1 and 0, cancelling out half of your calculation.

Try instead with (3.0 / 2) and (1.0 / 2)

...or simply 1.5 and 0.5.

tenfour
  • 36,141
  • 15
  • 83
  • 142